I cannot get the OpenService function to return a valid file handle (returns 0).
Below is some code which illustrates the point and is self explanatory.
Any help with this would be greatly appreciated.
I am using Borland Delphi 2005 on a XP Professional SP2 PC.
Thanks in advance.
hdlOpenService : SC_Handle;
ServStat : TServiceStatus;
dwStatus : DWORD;
dwStatus := DWORD (-1);
hdlOpenSCManager := OpenSCManager (Nil, Nil, SC_MANAGER_ALL_ACCESS);
if (hdlOpenSCManager > 0) then
hdlOpenService := OpenService(hdlOpenSCManager, PChar('Windows Management Instrumentation'), SC_MANAGER_ALL_ACCESS);
if hdlOpenService = 0 then
// hdlOpenService always equals zero despite the fact the the service is both installed and running. Other services I have tested have given me the same result.
// The error message is; "The specified service does not exist as an installed service"