Query/Control service on x64
Posted: Wed Oct 05, 2011 11:43 am
The code below ( I don't know who wrote it, I tried to search the forums)
I'm compiling the code to x86, but need it to run on both x86 and x64.
The code works fine on x86, but on x64 it does not. (always telling me that a system shutdown is in progress)
Is this going to be doable? If so, any tips on how to get it going on x64 (while still compiling to 32bits)
thanks!
-j
I'm compiling the code to x86, but need it to run on both x86 and x64.
The code works fine on x86, but on x64 it does not. (always telling me that a system shutdown is in progress)
Is this going to be doable? If so, any tips on how to get it going on x64 (while still compiling to 32bits)
thanks!
-j
Code: Select all
Structure Status
dwServiceType.l
dwCurrentState.l
dwControlsAccepted.l
dwWin32ExitCode.l
dwServiceSpecificExitCode.l
dwCheckPoint.l
dwWaitHint.l
EndStructure
Procedure.l QuerySvc(svcName.s)
Protected.l nStatus
Protected.Status service
Protected.l LastError = 0
Protected.l lpMachineName = #Null, lpDatabaseName = #Null,scmDesiredAccess = #SC_MANAGER_ALL_ACCESS,svcDesiredAccess = #SERVICE_ALL_ACCESS
Protected.l scmHandler = OpenSCManager_(lpMachineName, lpDatabaseName, scmDesiredAccess)
If scmHandler = #Null
LastError = GetLastError_()
dbgout("Open SCM failed with error " + Str(LastError))
Else
Protected svcHandler = OpenService_(scmHandler, svcName, svcDesiredAccess)
If svcHandler = #Null
LastError = GetLastError_()
dbgout("Open Service failed with error " + Str(LastError))
Else
Protected Result = QueryServiceStatus_(svcHandler, service)
If Result = 0
LastError = GetLastError_()
dbgout("Query failed with error " + Str(LastError))
Else
nStatus = service\dwCurrentState
dbgout("Service state: "+Str(nStatus))
EndIf
Result = CloseServiceHandle_(svcHandler)
EndIf
Result = CloseServiceHandle_(scmHandler)
EndIf
If LastError
nStatus = -1 * LastError
EndIf
ProcedureReturn nStatus
EndProcedure
OutputDebugString_("Query: "+Str(QuerySvc("mssqlserver")))