Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Service User Account Change Not Working?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Service User Account Change Not Working?
Divers
Thread ID:
00673839
Message ID:
00673839
Vues:
57
I am trying to change the logon user account from LocalSystem to a user account. The account already exists, is a member of the local Administrators group (not that that matters), and has "logon as a service" right. But I get an error code 22. Why does this not work?
Clear
oNet = CreateObject("Wscript.Network")
cHost = oNet.ComputerName
cHost = "."
cUserName = "aaa"
cPass="aaa"
cServiceName = "myservice"  && Try Spooler for your own system
? cHost + "   " + cUserName + "   " + cPass + "   " + cServiceName

oWMISvc = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" + cHost + "\root\cimv2")
colSvcs = oWMISvc.ExecQuery("Select * From Win32_Service Where Name='" + cServiceName + "'")
If colSvcs.Count != 1 Then
	? "Service Not Found"
	Cancel
EndIf

oWMISvc =    GetObject("WinMgmts:{impersonationLevel=impersonate}!root/cimv2")
cSvc = 'Win32_Service.Name="' + cServiceName + '"'
? cSvc

oMyService = oWMISvc.Get(cSvc)
oMethod = oMyService.Methods_("Change")
oParmIn = oMethod.inParameters.SpawnInstance_()
oParmIn.StartName = ( (cUserName) )
oParmIn.StartPassword = ( (cPass) )
oParmOut = oMyService.ExecMethod_("Change", oParmIn)

? oParmOut.ReturnValue
Thanks.
Répondre
Fil
Voir

Click here to load this message in the networking platform