Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to detect if you can run NT services Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
10-Oct-02
Category
System
Language
Delphi 2.x
Views
153
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

How can I detect if I can install and run a service on the current operating 
system? I was just going to detect the operating system, but I figured it might be 
better to directly detect the service control - but not sure how to do that.

Answer:

After installing a service (using the -install command line parameter) you can use 
the following code to start the service:
1   
2   function StartService(Name: string): boolean;
3   var
4     Scm: SC_HANDLE;
5     Service: SC_HANDLE;
6     p: pChar;
7   begin
8     Result := false;
9     Scm := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
10    if Scm <> 0 then
11    begin
12      Service := OpenService(Scm, pChar(Name), SC_MANAGER_ALL_ACCESS);
13      if Service <> 0 then
14      begin
15        p := nil;
16        if WinSvc.StartService(Service, 0, p) then
17          Result := True;
18        CloseServiceHandle(Service);
19      end;
20      CloseServiceHandle(Scm);
21    end;
22  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC