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!

changeserviceconfig

Status
Not open for further replies.

fatsheldon

Programmer
Apr 8, 2003
4
0
0
US
hi, i'm trying to change password for the account that a service uses at startup. much like the MSDN example "Changing the Password on a Service's User Account" except in VB not C.

I can OpenSCManager, OpenService and LockServiceDatabase with no problems, but ChangeServiceConfig always fails. here's my statements:

Declare Function ChangeServiceConfig Lib "advapi32.dll" Alias "ChangeServiceConfigA" (ByVal hService As Long, ByVal dwServiceType As Long, ByVal dwStartType As Long, ByVal dwErrorControl As Long, ByVal lpBinaryPathName As String, ByVal lpLoadOrderGroup As String, lpdwTagId As Long, ByVal lpDependencies As String, ByVal lpServiceStartName As String, ByVal lpPassword As String, ByVal lpDisplayName As String) As Long

errCode = ChangeServiceConfig(svcHandle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, _
vbNullString, vbNullString, 0&, vbNullString, vbNullString, "NewPassword13", vbNullString)
If errCode = 0 Then
MsgBox "LastDllError = " & CStr(Err.LastDllError)
UnlockServiceDatabase ByVal scmLock
CloseServiceHandle (svcHandle)
CloseServiceHandle (scMan)
setServicePasswd = 2
Exit Function
End If

I've managed to get lastdllerror 87 (invalid parameter?) and 997 (IO pending?).

Does anyone have example VB code on exactly how to call this function and/or the exact value i should be using for SERVICE_NO_CHANGE ?

This is frustrating me quite a bit. ok, a lot.

 
To make it work, you should add ByVal before 0& in the ChangeServiceConfig function call.

It should be :

errCode = ChangeServiceConfig(svcHandle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, _
            vbNullString, vbNullString, ByVal 0&, vbNullString, vbNullString, "NewPassword13", vbNullString)

The function should return a 1 instead of 0. It works very well for me.

 
thanks pearljamtwice.

I've had it working, but not only with the byval you mentioned. i was never able to get it working sending all NULLs except the passowrd so i wrote a small C .dll to do it and i call the .dll i wrote and only pass one parameter. it's kind of a hack-around, and i know it but i did it to make a point.

It doesn't work if you attempt to pass NULLs from VB to the Library call for the following two variables: LoadOrderGroup and TagID. you can read in the original values and send them back easy enough so, if you're not interested in doing it in C (and passing big fat NULLs like the MS example) then you can use the other library functions to get and store the values and just pass them back without changing them.

this was confirmed by Edward Hughes on the Microsoft.public.vb.database newsgroup. so, you can make it work from VB, but there's just a few handy things nice to know. thanks again for the post.

fatsheldon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top