• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4563
  • Last Modified:

Problem Running Batch File Windows Server 2003

Hello,

I have been looking all over various forums that keep describing the problem of running a scheduled batch file in Windows Server 2003 when you are not logged in. Most of the replys that I see usually say to make sure you run the file as Administrator and also to install the hotfix that corresponds to this problem. I have done both of the above and still no luck. The script runs fine when I am logged in but as soon as I log out it ceases to run. Under scheduled tasks it says that the file ran while I was not logged in but I know that this is not the case. Basically my batch script is being run to gather some information from the system (Win 2003 Server service pack 2) and pass this information (via CGI parameters) to a perl script that I have running on another server. I call start (name of url with params here)" which brings up Internet Explorer (the default browser) with the correctly loaded page. Every thing works perfect until I log off. I have heard (I dont know how correct this is) that the reason for this is due to the fact that Internet Explorer requires certain environment variables to be run and these variables are not set if I am logged off. Does anyone know if this is true and if so is there some way around this? Any help is appreciated, Thank you.

PS- am running Internet Explorer 7.0 thanks,
0
glassgiant
Asked:
glassgiant
  • 7
  • 6
6 Solutions
 
Richard QuadlingSenior Software DeveloperCommented:
I'm not on windows 2003, but here are some steps you could try ...

1 - Check the Scheduled Task log.

     Load Explorer.
     Open Control Panel.
     Open Scheduled Tasks.
     Choose View Log from the Advanced menu option.

     This will show you the start and stop of every scheduled task. Is the task running but failing or not running at all?

2 - Create a really dumb batch file (test.bat)

ECHO Running dumb script at %DATE% %TIME% >> C:\Test.Log

Run this manually and make sure there are no errors and that the log file is created.

3 - Set this as a task to run every minute or so.

4 - Check the C:\Test.log and the Scheduled Task log to make sure everything is still running correctly.

5 - Logoff.

6 - Wait a bit.

7 - Log back in and check the logs.

8 - Shutdown and reboot but don't login for several minutes.

9 - Login and check the logs again.


Now report back all that happened.
0
 
StuFox100Commented:
You are correct that some variables don't work. I always use the full file path for all things I call (including perl). This might be an issue if it is actually running as scheduled.

Cheers
Stu
0
 
glassgiantAuthor Commented:
When Im logged in the task log gives an exit code of 0 but when I am not logged in it gives an exit code of 80. I created a very simple perl file that just prints Test to an txt file in the same directory. Again everything is perfect when I am logged in but when I am not logged in the task says it runs but with an exit code of 80 and nothing is printed to the screen. I have looked this exit code up and found that I should disable HID Input Service. I checked and this service is already disabled. The settings for running the perl file under scheduled tasks are:

Run : C:\Perl\bin\perl.exe "C:\filepath\test.pl"
Start In: C:\Perl\bin
Run as : have tried both as myself (I have Admin privaleges) and as Administrator account both have same effect.
I have the task set to run every minute, I do not have "run only if I am logged on" checked

Thank you for your replies.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Richard QuadlingSenior Software DeveloperCommented:
The exit code you have is gnerated by Perl. 0x80 = 128


Can you remove perl from the equation and use the batch file I created.

So ...

Run: C:\Test.BAT
Start In: C:\
Run As: whoever is appropriate.

If you use the following batch file (see snippet below), you will see the exit code of 99 is used. This should be shown as 0x63 in the scheduler log file.


@ECHO OFF
ECHO Running dumb script at %DATE% %TIME% >> C:\Test.Log
EXIT /B 99

Open in new window

0
 
glassgiantAuthor Commented:
Hi.

K ran the simple batch file as specified above and it gave 63 in the log file as exit code when I was logged in and 80 when I was not logged in.

Thanks for your help RQuadling.
0
 
Richard QuadlingSenior Software DeveloperCommented:
When you were not logged in and it was running every minute or so, did it write to the C:\Test.log correctly?

I do have the disadvantage here that I cannot get my setup to go wrong.


So, create a new login.

Use this user as the account for the Scheduler Service.

Also use it for the actual task.

Make sure the log files (the scheduler and the test.log) are actually being written to.

0
 
glassgiantAuthor Commented:
It seems to be writing to the log file correctly whether I am logged in or not. However it generates different codes depending if I am logged in (63 when logged in and 80 when not, this is for the simple batch file that you got me to run).
0
 
Richard QuadlingSenior Software DeveloperCommented:
So we know that the scheduler is operating and a batch file can be run.

What happens if you amend the batch file to the snippet below.

If this works, at least your script can run and we can concentrate on the error.

As a batch file is giving the wrong error, I don't think it has anything to do with the script (batch or perl) itself.


@ECHO OFF
ECHO About to run the Perl program at %DATE% %TIME% >> C:\Test.Log
C:\Perl\bin\perl.exe C:\filepath\test.pl
ECHO Completed the Perl program at %DATE% %TIME% >> C:\Test.Log
EXIT /B %ERRORLEVEL%

Open in new window

0
 
glassgiantAuthor Commented:
I modified the batch file like you said. It ran fine and exited with a code of 0 when I was logged in. The perl file also executed when called by the batch when I was logged in. When I logged off the log says the task completed with an exit code of 80  but nothing was written to the test log and the perl file (which also writes to a test log) did not execute either.
0
 
Richard QuadlingSenior Software DeveloperCommented:
I have to admit I'm lost. I can't see why begin logged in should have any effect on the scheduler.

Have you set a user name and password on the task itself. I think there is a "Set Password" option.

If you go the list of tasks using Explorer, on the Tools menu there is the AT Service Account.

Is this high enough?

Does the task have permissions? Temporarily allow everyone full access.

It must be a permissions issue. Do the event logs hold any information about the task?

0
 
glassgiantAuthor Commented:
I tried running the task under "NT Authority\System" but still nothing. Ive also tried running the task using the actualy Administrator username/pass as well as my own which has full priviledges still to no avail. Whats even more baffling is that we are running several servers (all windows 2003 server service pack 2) on which I can run tasks fine when not logged in. However, I cannot seem to find the difference in any settings, maybe there is some sort of fix installed that I do not know about other than the MS hotfix. Anyway, I have since moved on to a workaround on this issue but would like to thank you for all your help.
0
 
Richard QuadlingSenior Software DeveloperCommented:
I'm really sorry that I couldn't get a solution for you. Hey if it was easy, we'd have the monkeys doing it for us.

What is the workaround?


0
 
glassgiantAuthor Commented:
Workaround was to give the person who needs the result of the file access to the server to run it themselves.  Not elegant, but works :o)
0
 
glassgiantAuthor Commented:
Oh, and thanks for all your work on this.  I really appreciate it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now