I am trying to change the actions taken by an NT service in the case of a failure(eg. Restart the service, Take No Action). This can only be tested on windows OS 2000 and later.
I have written the function changeserviceconfig2, but it doesn't seem to do anything. It just returns 0.
The OpenSCManager function and the OpenService function both seem to work ok.
Has anybody successfully written this function. Any help will be appreciated. Thankyou.
Here is what I have done.
Public Function RecoveryAction(ByVal ServiceName As String) As Long
Dim hSCManager As Long
Dim hService As Long
Dim CSC As Long
hSCManager = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_CONNECT)
' If hSCManager <> 0 Then
hService = OpenService(hSCManager, ServiceName, SERVICE_CHANGE_CONFIG)
MsgBox "VALUE OF hSCManager IS: " & hSCManager
MsgBox "VALUE OF hService IS: " & hService
If hService <> 0 Then
' If service is NOT running
MsgBox "SERVICE NOT RUNNING"
'hService = SERVICE_CHANGE_CONFIG
CSC = ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, SC_ACTION_RUN_COMMAND)
MsgBox "CSC = " & CSC
'If one of the specified service controller actions is SC_ACTION_RESTART,
'hService must have the SERVICE_START access right
' If ChangeServiceConfig2(hService, SC_ACTION_RESTART, 0) Then
' hService = SERVICE_START
MsgBox " I entered this loop"
CloseServiceHandle hService
' End If
CloseServiceHandle hSCManager
End If
' End If
End Function
I have written the function changeserviceconfig2, but it doesn't seem to do anything. It just returns 0.
The OpenSCManager function and the OpenService function both seem to work ok.
Has anybody successfully written this function. Any help will be appreciated. Thankyou.
Here is what I have done.
Public Function RecoveryAction(ByVal ServiceName As String) As Long
Dim hSCManager As Long
Dim hService As Long
Dim CSC As Long
hSCManager = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_CONNECT)
' If hSCManager <> 0 Then
hService = OpenService(hSCManager, ServiceName, SERVICE_CHANGE_CONFIG)
MsgBox "VALUE OF hSCManager IS: " & hSCManager
MsgBox "VALUE OF hService IS: " & hService
If hService <> 0 Then
' If service is NOT running
MsgBox "SERVICE NOT RUNNING"
'hService = SERVICE_CHANGE_CONFIG
CSC = ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, SC_ACTION_RUN_COMMAND)
MsgBox "CSC = " & CSC
'If one of the specified service controller actions is SC_ACTION_RESTART,
'hService must have the SERVICE_START access right
' If ChangeServiceConfig2(hService, SC_ACTION_RESTART, 0) Then
' hService = SERVICE_START
MsgBox " I entered this loop"
CloseServiceHandle hService
' End If
CloseServiceHandle hSCManager
End If
' End If
End Function