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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objService.Change returns 21

Status
Not open for further replies.

BKearan

IS-IT--Management
Sep 27, 2007
45
US
I have a service that I need to script to set a user name and password for.
When opening it is says something about the device associated with it does not exist.
When scripting to change the user name and password, it returns error 21, device not ready ( I think ).

How can I get around this and change the user name and password?

Here is a snippit... ( I am wrapping it in an HTA, hence the document.writeln stuff...)

Code:
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='WksCfgSrv'")

For Each objService in colServiceList
    stoperror = objService.StopService()
'((Sleep code here ))
	objdocument.writeln("<br>Stop error was " & stoperror & "<br>")
   
    r = objService.Change( , , , , , , serviceUser, servicePass)
	objdocument.writeln(objservice.name & "<br>")
    if r = 0 then
        msg = msg & "<br>Updated logon for " & objService.Name & " ok"
    else
	objdocument.writeln("<br><br>Error level is " & r)
	objdocument.writeln("<br>" & err.description)
        msg = msg & "<br>ERROR: could not update logon for " & objService.Name
    End If
 
The return value for the Change method of this class 21 = Status Invalid Parameter.

You may want to look at the documentation and make sure you are providing the correct information.



--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
From
I get :

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Service WHERE StartName = '.\\NetSvc'")
For Each objService in colServices
 errServiceChange = objService.Change _
 ( , , , , , , ".\LocalSystem" , "")
Next

Pretty much following that explicitly. Don't know where else to look for documentation.

Trying playing with the spaces in the objService.Change line...
 
'i am a stickler for avoid shelling out where possible but shortcuts can be nice sometimes
<command>%systemroot%\system32\sc</command>
<parameters>
<parameter>config %service_name_here% obj= LocalSystem type= own</parameter>
</parameters>
'a more explicit way of declaring parameters for the service change method?
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

strQuery = "Select * from Win32_Service where Name = '" & sService & "'"
Set colServiceList = objWMIService.ExecQuery(strQuery)

For Each objService in colServiceList
Wscript.Echo objService.Caption
Set oMethod = objService.Methods_("Change")
Set oInParam = oMethod.inParameters.SpawnInstance_()
oInParam.StartMode = sStartMode
oInParam.StartName = sStartName
oInParam.StartPassword = sStartPassword
Set oOutParam = objService.ExecMethod_("Change", oInParam)
Next

Set colServiceList = Nothing
Set objWMIService = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top