Solved

Problem Running Batch File Windows Server 2003

Posted on 2008-06-19
14
4,202 Views
Last Modified: 2008-07-22
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
Comment
Question by:glassgiant
  • 7
  • 6
14 Comments
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 125 total points
ID: 21827310
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
 
LVL 12

Expert Comment

by:StuFox100
ID: 21830450
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
 
LVL 1

Author Comment

by:glassgiant
ID: 21832027
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
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 125 total points
ID: 21832241
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
 
LVL 1

Author Comment

by:glassgiant
ID: 21846565
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
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 125 total points
ID: 21850088
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
 
LVL 1

Author Comment

by:glassgiant
ID: 21855735
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 125 total points
ID: 21863611
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
 
LVL 1

Author Comment

by:glassgiant
ID: 21884238
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
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 125 total points
ID: 21888307
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
 
LVL 1

Author Comment

by:glassgiant
ID: 21975763
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
 
LVL 40

Expert Comment

by:RQuadling
ID: 21980823
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
 
LVL 1

Author Comment

by:glassgiant
ID: 21990008
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
 
LVL 1

Accepted Solution

by:
glassgiant earned 0 total points
ID: 21990012
Oh, and thanks for all your work on this.  I really appreciate it.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now