Link to home
Start Free TrialLog in
Avatar of SuttonJ1
SuttonJ1

asked on

Calling a batch file from a windows service.

I am setting up MRTG to create graphs that show the number of files in a folder (Mail queue).
I created a batch file that will check the folder and return the number of files.
In MRTG, I've created my .cfg file that will call the batch file.  It works from the command line.
It logs and creates the graphs fine.

I used SRVANY and INSTSRV to create the MRTG service and it is configured correctly.  The service runs, but no data is collected, because (I'm sure) that the batch file is not running.

So I need to know if it is possible to call a batch file from a windws service?
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

open a processing for cmd.exe like so:

c:\windows\system32\cmd.exe /c yourbatchfile.bat

Good Luck,
Steve
ASKER CERTIFIED SOLUTION
Avatar of jkorsak
jkorsak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Caudax
Caudax

Yes, it is possible to call a batch from a Windows service; however, I believe you need to activate "allow service to interact with desktop" in order for it to run.

I think this is your problem.

If you want to rectify this, you may either go to services.msc (which can also be accessed by compmgmt.msc) or you could use srvmgr.exe
Avatar of SuttonJ1

ASKER

Everyone, Thanks for the suggestions.
I had already tried the "Allow service to interact with Desktop" and it didn't work.
I'm not sure about SteveGTR suggestion, as the service was actually created from a Perl script, and I'm not sure exactly what Steve was suggesting.  Only reason I didn't try it was becuse I thought Caudax suggestion would be easier to try, and I would swear that I tried it on Friday and it didn't work, however this morning, I decided to gibe it another shot just to make sure.  I set it to run using Domain Admin credentials, and it seems to be running fine.
SuttonJ1,

Many people get caught by the fact that the user "Local System" does not have any network access by default (at least in Win2k sp2 or later I think).  So they test using files on the local drive and then when they try to go live and get a file or access something from a remote drive it fails.  Just for safety, and because I'm paranoid by nature, I would create a new user that is only used for running this batch file.  Give that user account only access to the folders needed for the batch file.  Thanks for the points.

John
Well, if I'm not much mistaken, "Local System" does have network access if it's run on the domain controller's computer. At any rate, my mistake for neglecting that this was being run on such a network.