Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changeserviceconfig2 in VB

Status
Not open for further replies.

VL304

Programmer
Sep 15, 2003
2
0
0
AU
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 &quot;VALUE OF hSCManager IS: &quot; & hSCManager
MsgBox &quot;VALUE OF hService IS: &quot; & hService
If hService <> 0 Then
' If service is NOT running
MsgBox &quot;SERVICE NOT RUNNING&quot;
'hService = SERVICE_CHANGE_CONFIG

CSC = ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, SC_ACTION_RUN_COMMAND)

MsgBox &quot;CSC = &quot; & 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 &quot; I entered this loop&quot;
CloseServiceHandle hService
' End If
CloseServiceHandle hSCManager
End If
' End If
End Function

 
I'm not familiar with the function but I had a quick look at the documentation. The second paramater in:

CSC = ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, SC_ACTION_RUN_COMMAND)

is a SERVICE_FAILURE_ACTIONS structure which contains a pointer to a SC_ACTION structure. AFAIK, VB can't include pointers in a structure.

There would have to a &quot;B&quot; version of the function (as there is for some MAPI functions) where the two structures are passed in separate parameters but I don't think there is one in this case.

Paul Bent
Northwind IT Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top