Solved

delphi, Win8 and Services

Posted on 2014-04-28
8
638 Views
Last Modified: 2014-05-14
Hi

I have the following code in a service:
   h_manager := OpenSCManager(PChar(Machine), nil, SC_MANAGER_CONNECT);
   if h_manager > 0 then
   begin
     h_svc := OpenService(h_manager, PChar(ServiceName),
       SERVICE_START or SERVICE_QUERY_STATUS or SERVICE_ALL_ACCESS);
     if h_svc > 0 then
     begin
     end;
  end;

Open in new window

If I compile it with D XE2 and run it on a Win7-machine, h_svc  has a correct value and I can work with it. If I compile it in D XE5 and run it on a Win8-machine (I changed my developpement-machine), h_svc is alway zero. If I only have QUERY_STATUS as Parameter it is ok. So I guess that this is a policy-problem. (btw: the service is SQL Server) How can I solve this? Thanks for every hint, Peter
0
Comment
Question by:formi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40028133
I think so too. Why you need SERVICE_ALL_ACCESS? what do you need to do with this service? Maybe you can add SERVICE_STOP and SERVICE_PAUSE_CONTINUE and probably need to extended sc manager access with some of
  SC_MANAGER_CONNECT             = $0001;
  SC_MANAGER_CREATE_SERVICE      = $0002;
  SC_MANAGER_ENUMERATE_SERVICE   = $0004;
  SC_MANAGER_LOCK                = $0008;
  SC_MANAGER_QUERY_LOCK_STATUS   = $0010;
  SC_MANAGER_MODIFY_BOOT_CONFIG  = $0020;

  SC_MANAGER_ALL_ACCESS          = (STANDARD_RIGHTS_REQUIRED or
                                    SC_MANAGER_CONNECT or
                                    SC_MANAGER_CREATE_SERVICE or
                                    SC_MANAGER_ENUMERATE_SERVICE or
                                    SC_MANAGER_LOCK or
                                    SC_MANAGER_QUERY_LOCK_STATUS or
                                    SC_MANAGER_MODIFY_BOOT_CONFIG);

Open in new window

0
 

Author Comment

by:formi
ID: 40029104
You may be right all Access is not necessary, but I want to start/stop the service and SERVICE_START does not work.
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40029119
Try (SERVICE_START + SERVICE_STOP + SERVICE_INTERROGATE)
Constants from : http://msdn.microsoft.com/en-us/library/ms685981%28v=VS.85%29.aspx

If it fail again - get returning error code  
...
h_svc := OpenService(h_manager, PChar(ServiceName),
       SERVICE_START or SERVICE_QUERY_STATUS or SERVICE_ALL_ACCESS);
     if h_svc > 0 then
     begin
     end
     else
     begin
        RaiseLastOsError(); ///or ger error code with GetLastError.
     end;

Open in new window


more info: http://msdn.microsoft.com/en-us/library/ms686321%28v=vs.85%29.aspx
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:formi
ID: 40062877
Unfortunately it didn't help. I can not start/stop Services. Any other ideas?
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40062972
Did you get error code? (using RaiseLastOsError or
ShowMessage('Error: '+ SysErrorMessage(GetLastError)) ;

Open in new window

0
 

Author Comment

by:formi
ID: 40063763
The message is "Access denied". I now tried to install the Service manually and I get the same error. If I open a cmd-window "as Administrator" I can install it. So the question is how can I run a program "as administrator" in the IDE to debug it?
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40063770
Quite easy - impersonate current user - this blogs show you how:
http://www.michael-puff.de/Programmierung/Delphi/Code-Snippets/Impersonate.shtml
http://www.delphibasics.info/home/delphibasicssnippets/impersonateuser

...never tried - but maybe if you run delphi ide as admin .. childe process (your app) should be run as admin too.
0
 

Author Closing Comment

by:formi
ID: 40063828
Thanks, that really works: running the IDE as admin.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to renew a Delphi rad-studio licence? 5 95
Delphi inherited method 6 89
Delphi...Split view - idea? 1 148
Browsing a TTreeView in Delphi 5 50
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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