formi
asked on
delphi, Win8 and Services
Hi
I have the following code in a service:
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;
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
ASKER
You may be right all Access is not necessary, but I want to start/stop the service and SERVICE_START does not work.
Try (SERVICE_START + SERVICE_STOP + SERVICE_INTERROGATE)
Constants from : http://msdn.microsoft.com/ en-us/libr ary/ms6859 81%28v=VS. 85%29.aspx
If it fail again - get returning error code
more info: http://msdn.microsoft.com/ en-us/libr ary/ms6863 21%28v=vs. 85%29.aspx
Constants from : http://msdn.microsoft.com/
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;
more info: http://msdn.microsoft.com/
ASKER
Unfortunately it didn't help. I can not start/stop Services. Any other ideas?
Did you get error code? (using RaiseLastOsError or
ShowMessage('Error: '+ SysErrorMessage(GetLastError)) ;
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that really works: running the IDE as admin.
Open in new window