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

Script to change service account used by services

Status
Not open for further replies.
Sep 20, 2006
10
GB
I'm having to change the account used by some services spread over a vast
number of servers and naturally I don't want to do this manually.

Unfortunately the organisation I work for is overly secure, so the password
for the accounts to be used are not known by any one person.
Instead each password is broken down into two halves and two different
people would have each half.
The commands I think I will need to use are essentially:

Set service_name=

FOR /f "tokens=1" %%servername IN (c:\SvcActPwd\server.txt)

SET server=%servername

psexec \\%server% sc config %Service_Name% obj= [DOM\User] password=%password%

A couple of points:
1) The text file specified will have a number of server names in it.
2) The service_name will be set to the actual service name by the person
running the script.
3) Psexec is a utility which allows you to easily execute commands on a
remote system.
4) I need to input the password securely i.e. the two people typing the
password in can't see the other half, so a prompt with either stars (*) or
blanks is needed.
I haven't been able to find a way to input that as the script runs, but I
might just not now what I'm really looking for.

Alternately I could have two files each with one half of the password and
input them.
I guess I'd have to do this:

FOR /f "tokens=1" %%password1 IN (c:\SvcActPwd\pass1.txt)
FOR /f "tokens=1" %%password2 IN (c:\SvcActPwd\pass2.txt)
Set pass1=%password1
Set pass2=%password2
psexec \\%server% sc config %Service_Name% obj= [DOM\User]
password=%pass1%%pass2%

Does this look right?
I'm fairly new to this type of advanced cmd scripting as I have mostly done
simple(ish) batch files before.

Many thanks for any help/comments...

Cheerio,
Lars Petersson
 
Found this in the MS Scriptcenter Repository (downloadable from MS)

Modify Service Accounts
Description
Changes the service account to LocalService for any services running under the hypothetical service account Netsvc.
__________________________________________________________
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 _
( , , , , , , "NT AUTHORITY\LocalService" , "")
Next
__________________________________________________________

Hope this helps.

 
Thanks, but unfortunately that's VB Script which I don't know well enough to try with.
It also doesn't tick all the boxes of what I need...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top