Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bundling resource BAT files but can't execute

Status
Not open for further replies.

Tony1l

Programmer
Dec 21, 2002
30
US
I've had a heck of a time trying to create routines that kill and restart services in WinXP. I've found the easiest method to write a (DOSCOMMAND) BAT file using the 'SC' command to start/stop them. I have been planning on dumping these bat files into a folder and calling them with ShellExecute with SW_HIDE and actually that's already working pretty well...but I'd rather bundle them within the executable as a resource which I've spent some time on but haven't been able to find the proper way to execute them. Can I call ShellExecute for a resource BAT file? I would greatly appreciate any suggestions.

Thanks
Tony
 
Guess you would be better off using ShellExec API calls to get your services stuff going, next to actually interfacing to the services API calls themselves ofcourse.

HTH
Ath
 
Tonhu:

Sorry for "translating" you, but your post is a little hard to understand :) :).

Tony:

TonHu is telling you to use the ShellExecute function to run SC.EXE. It is in the ShellAPI unit and you can find help in the SDK.

Way better than your BAT approach.

buho (A).

 
I was set on taking a particular course. During testing I encounterd a problem that lead me to give up on executing the command directly but after the suggestion I revisted and had no trouble making this work with something like the following...

ShellExecute(Handle, 'open', 'SC.exe', 'stop ServiceName', nil, SW_hide);

I've seen other examples of controlling services that are much more complex. I try to always choose the least complicated solution.

Thanks so much
Tony
 
Usually I try to use the most autonomous (self-contained) way. But writing code to communicate with the services mannager only to start/stop a service is a little to much, no doubt.

Now, if you are writing services yourself you have the code at your fingertips; and if you are planning to write services in the near future it is a good place to start.

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top