7.5. Setting the Service Account and Password


You want to configure the account and password used by a service.


Using a graphical user interface

  1. Open the Services snap-in.

  2. In the left pane, double-click on the service you want to configure.

  3. Click the Log On tab.

  4. Select This Account.

  5. Enter the domain and username of the account or click Browse to find it.

  6. Enter and confirm the account's password.

  7. Click OK.

Using a command-line interface:

> sc config <ServiceName> obj= <Domain>\<Username> password= <Password>

The following command configures the MyMonitor service to log on using the local administrator account:

> sc config MyMonitor obj= FS-RTP01\administrator password= foobar

Using VBScript

' This code configures the service account
strUser     = "<Domain>\<Username>"  ' e.g., FS-RTP01\administration
strPassword = "<Password>"       ' e.g., foobar
strSvcName  = "<ServiceName>"    ' e.g., MyMonitor
strComputer = "<ServerName>"     ' e.g., fs-rtp01 (use . for local server)
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objService = objWMI.Get("Win32_Service.Name='" & strSvcName & "'")
intRC = objService.Change(,,,,,,strUser,strPassword)
if intRC > 0 then
   WScript.Echo "Error setting service account: " & intRC
   WScript.Echo "Successfully set service account"
end if


If you need to configure a user account to run a service under, make sure the account has the Log on as service right. Without ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.