?
Solved

Start NT Service and Stop

Posted on 2000-01-20
4
Medium Priority
?
370 Views
Last Modified: 2010-04-06

How can i start an NT service and stop it or change?
0
Comment
Question by:lulli
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2372084
HI
ive not a direct answer but there's alot of service stuff here which may help:

http://www.jgsoftware.com/nt.htm
0
 

Author Comment

by:lulli
ID: 2373637
I just need an example in code,,,
0
 
LVL 1

Accepted Solution

by:
schutnik earned 90 total points
ID: 2378320
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
 

Expert Comment

by:krypto2000
ID: 12370384
The type is
 
    hSC : SC_HANDLE
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Suggested Courses
Course of the Month6 days, 18 hours left to enroll

593 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