Posted 23 August 2007 - 01:17 AM
I had a problem with BootSDI as I continuously run a mounted vmware image on my computer -- so the vdk service is already running, which causes problems for the script as it assumes that the service needs to be installed.
The following autoit script detects the status of the vdk service:
VDKcheck.au3
[codebox]Global $SC_MANAGER_CONNECT = 0x0001
Global $SERVICE_INTERROGATE = 0x0080
Global $SERVICE_CONTROL_INTERROGATE = 0x00000004
If _ServiceRunning("VirtualDK") = 1 Then
$file = FileOpen($CmdLine[1],2)
FileWriteLine($file,"[VDKcheck]")
FileWriteLine($file,"Status=ServiceRunning")
FileClose($file)
ElseIf _ServiceExists("VirtualDK") = 1 Then
$file = FileOpen($CmdLine[1],2)
FileWriteLine($file,"[VDKcheck]")
FileWriteLine($file,"Status=ServiceExists")
FileClose($file)
Else
$file = FileOpen($CmdLine[1],2)
FileWriteLine($file,"[VDKcheck]")
FileWriteLine($file,"Status=ServiceNonexistent")
FileClose($file)
EndIf
;===============================================================================
;
; Description: Checks to see if a service is installed
; Syntax: _ServiceExists($sServiceName)
; Parameter(s): $sServiceName - Name of service to check
; Requirement(s): None
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; Author(s): SumTingWong
; Documented by: noone
;
;===============================================================================
Func _ServiceExists($sServiceName)
Local $arRet
Local $hSC
Local $bExist = 0
$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
"str", "", _
"str", "ServicesActive", _
"long", $SC_MANAGER_CONNECT)
If $arRet[0] <> 0 Then
$hSC = $arRet[0]
$arRet = DllCall("advapi32.dll", "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", $SERVICE_INTERROGATE)
If $arRet[0] <> 0 Then
$bExist = 1
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $arRet[0])
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
EndIf
Return $bExist
EndFunc
;===============================================================================
;
; Description: Checks to see if a service is running
; Syntax: _ServiceRunning($sServiceName)
; Parameter(s): $sServiceName - Name of service to check
; Requirement(s): None
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; Author(s): SumTingWong
; Documented by: noone
;
;===============================================================================
Func _ServiceRunning($sServiceName)
Local $arRet
Local $hSC
Local $hService
Local $bRunning = 0
$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
"str", "", _
"str", "ServicesActive", _
"long", $SC_MANAGER_CONNECT)
If $arRet[0] <> 0 Then
$hSC = $arRet[0]
$arRet = DllCall("advapi32.dll", "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", $SERVICE_INTERROGATE)
If $arRet[0] <> 0 Then
$hService = $arRet[0]
$arRet = DllCall("advapi32.dll", "int", "ControlService", _
"long", $hService, _
"long", $SERVICE_CONTROL_INTERROGATE, _
"str", "")
$bRunning = $arRet[0]
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
EndIf
Return $bRunning
EndFunc[/codebox]
The script assumes the passing of a commandline argument in the form of something like:
[code]ShellExecute,Hide,"%Tools%\vdk\VDKcheck.exe","%Tools%\vdk\VDKcheck.txt"[/code]
Then the status of the service can be called from the written txt file and the currently installed service used or the service installed if that is required:
[code]IniRead,"%Tools%\vdk\VDKcheck.txt","VDKcheck","Status","%VDKcheck%" If,"%VDKcheck%",Equal,"ServiceExists",ShellExecute,Hide,"vdk.exe","start" If,"%VDKcheck%",Equal,"ServiceNonexistent",ShellExecute,Hide,"%Tools%\vdk\vdk.exe","install" If,"%VDKcheck%",Equal,"ServiceNonexistent",ShellExecute,Hide,"%Tools%\vdk\vdk.exe","start"[/code]
etc...
Just a suggestion.
Regards,
Galapo.