I need to get services "where startname = 'domain\user'"
Here's what I'm working with:
I need to do number 1, query based on a variable.
I thought I would troubleshoot by doing 2, but it doesn't work either.
Only #3 gives me some results, namely the names of the services & the accounts they start under. The 'startname' of the service I'm looking to change is a perfect, case sensitive match with the string 'domain\user', but the where won't work for me.....
Also, the error trap shows nothing on 1, 2, or 3.
But I do get Error: 0x80041017 Source: (null) on the 'For Each objService' for both 1 & 2 (I think because the 'where' clause finds no matches?)
If anyone sees any obvious (or not so obvious) errors, please point me in the right direction.
Thanks, And have a great year!
David J.
Here's what I'm working with:
Code:
OldUser = "domain\user"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
If Err.Number <> 0 Then
Wscript.Echo Computer & " is not reachable"
Else
' 1 Set colServices = objWMIService.ExecQuery ("Select * From Win32_Service Where StartName = '" & OldUser & "'")
' 2 Set colServices = objWMIService.ExecQuery ("Select * From Win32_Service Where StartName = 'domain\user'")
' 3 Set colServices = objWMIService.ExecQuery ("Select * From Win32_Service")
If Err.Number <> 0 Then
Wscript.Echo err.number & vbcrlf & err.description
End if
For Each objService in colServices
wscript.echo objService.name & vbcrlf & objService.Startname
' errReturn = objService.Change( , , , , , , newuser , pw)
objFileRpt.WriteLine "On Server " & Computer &", Changing User for service " & objService.name & " from " & OldUser & " to " & Newuser
serv = serv + 1
Next
End If
I need to do number 1, query based on a variable.
I thought I would troubleshoot by doing 2, but it doesn't work either.
Only #3 gives me some results, namely the names of the services & the accounts they start under. The 'startname' of the service I'm looking to change is a perfect, case sensitive match with the string 'domain\user', but the where won't work for me.....
Also, the error trap shows nothing on 1, 2, or 3.
But I do get Error: 0x80041017 Source: (null) on the 'For Each objService' for both 1 & 2 (I think because the 'where' clause finds no matches?)
If anyone sees any obvious (or not so obvious) errors, please point me in the right direction.
Thanks, And have a great year!
David J.