Start NT Service and Stop


How can i start an NT service and stop it or change?
lulliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
HI
ive not a direct answer but there's alot of service stuff here which may help:

http://www.jgsoftware.com/nt.htm
0
lulliAuthor Commented:
I just need an example in code,,,
0
schutnikCommented:
to start the service...
var
  hSC, hServ : THandle;
begin
  hSC := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
  // check for valid hSC!
  hServ := OpenService(hSC, 'ServiceName', SERVICE_START);
  // check for valid hServ
  StartService(hServ, 0, nil);
end;

to stop/pause/etc. service...
replace StartService line with the following:

  ControlService(hServ, <x>, nil);

where x is SERVICE_CONTROL_STOP , SERVICE_CONTROL_PAUSE, SERVICE_CONTROL_CONTINUE, etc.

you also need to ask for the permission you need in the OpenService (i.e. if you want to stop the service, replace SERVICE_START with SERVICE_STOP, etc.)

You might need to include the SVCMGR unit (or something like this)

Also, my types might be wrong (THandle) because I didn't test this code in Delphi.  If they are, just find the functions in the Delphi Source\RTL\Win directory and look for the parameter types (and include that unit in your code)

Good luck,
Kelly
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
krypto2000Commented:
The type is
 
    hSC : SC_HANDLE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.