Scripting Service Account Changes

I recently had a situation where I needed to script the creation of a Windows service and specify a domain user/password to run the service.  The main struggle was getting the service to grant the user “Log On As Service” rights, which wasn’t being automatically completed with the SC.exe tool.  To accomplish this feat, the NTRights.exe utility from the Windows Server 2003 Resource Kit was needed, and will be needed for the below script!

sc.exe create "My Service" type= own start= auto binpath= "C:\Program Files\Product\MyApp.exe"
sc.exe config "My Service" obj= "domain\username" password= "thePassword" type= own
"ntrights.exe" -u domain\username +r SeServiceLogonRight
sc.exe start "My Service"



Written by , Posted .

Leave a Comment

You must be logged in to post a comment.