On Error Resume Next iaComputers = «services.txt» Dim iPass Sub Error_(i) If Err<>0 Then s = Err.Number WScript.echo «Error « & s & « « & Err.Description If i<>0 Then Err.Clear End If End Sub Set Args = WScript.Arguments Sub chSvcPass(svc) On Error Resume Next Wscript.Echo «Change password for service «+svc i = inStr(svc, «») If i>0 Then host = Left(svc, i — 1) svc = Mid(svc, i + 1, 255) Set objWMIService = GetObject(«winmgmts:» _ & «{impersonationLevel=impersonate}!» & host & « ootcimv2») Set colServiceList = objWMIService.ExecQuery _ («Select * from Win32_Service») Error_(1) For Each objservice in colServiceList If objService.Name=svc Then errReturn = objService.Change( , , , , , , , iPass) Error_(1) Wscript.Echo «Trying to stop «+svc objService.StopService() Error_(1) WScript.Sleep 2000 objService.StartService() Wscript.Echo «Trying to start «+svc Error_(1) End If Next End If End Sub Sub chUserPass(user) On Error Resume Next Wscript.Echo «Changing password for «+user WScript.StdOut.Write «Enter new password:» iPass=WScript.StdIn.Readline() user = Replace(user, «», «/») Set oUser = GetObject(«WinNT://» & user) Error_(1) oUser.SetPassword(iPass) oUser.SetInfo() Error_(1) End Sub Sub ReadHostFile(filename) Dim fso, f On Error Resume Next Set fso = CreateObject(«Scripting.FileSystemObject») Wscript.Echo «Read hosts file «+filename Set f = fso.OpenTextFile(filename, 1, False) if Err.Number<>0 then Call Error_(0) Else While Not f.atEndOfStream s = f.ReadLine chUserPass(s) svc = «svc» While Not f.atEndOfStream and svc<>»» svc = f.ReadLine If svc<>»» Then Call chSvcPass(svc) End If Wend Err.Clear Wend f.Close end if End Sub for i=0 to args.count-1 If Args(i) = «-f» Then iaComputers = Args(i+1) End If Next If Err=0 Then Call ReadHostFile(iaComputers) End If If Err<>0 Then Wscript.Echo «» Wscript.Echo «svcpwd [-f filename] « Wscript.Echo «» Wscript.Echo «-f file with acounts and services « Wscript.Echo «by default — services.txt « End If |