Script the creation of local user accounts for Commerce Server 2007

Posted by Wade on June 13, 2007

I’ll be honest … I’m lazy.  I hate doing repetitive things over, and over, and over again.  So, while I was going through and installing Commerce Server 2007 on a new virtual machine, I decided to script out the creation of the local user accounts.  Before we get to the script, a little background …


It is recommended that you create multiple accounts to handle the various roles within Commerce Server (such as the four web services, staging, etc).  In a production environment, these should be created as Domain accounts; however, in development (or the virtual world) you may not have access to, or wish to use, a domain. Consequently, you can create these users as local accounts as well.


Below is a script that will go ahead and create these local users for you (if I have time I’ll create a similar script for domain accounts).  Copy the text (or download the link) and save it to a .vbs file.  You should be able to simply double-click the file, and then open up Local Users and Groups under Computer Management to double-check.



‘ =====================================================
‘ Author:        Wade Wegner
‘ Create date:   06/13/2007
‘ Description:   Automate the creation of CS 2007 users
‘ File Name:     CreateCS2007LocalUsers.vbs

‘ =====================================================

‘ Set the local computer name
strComputer = “.”

‘ Run the Load method
Load

‘ Encapsulates the processing of this script
Sub Load()

   ’ Create the CS 2007 users
   CreateUser “CatalogWebSvc”,“Pa$$w0rd”,“Account for running the Catalog Web service”
   CreateUser “CSDMSvc”,“Pa$$w0rd”,“Account for running the Commerce Server Direct mailer service”
   CreateUser “CSHealthMonitorSvc”,“Pa$$w0rd”,“Account for running the Commerce Server health Monitoring service”
   CreateUser “CSLOB”,“Pa$$w0rd”,“Account for running the Commerce Server adapters”
   CreateUser “CSStageSvc”,“Pa$$w0rd”,“Account for running the Commerce Server Staging service”
   CreateUser “MarketingWebSvc”,“Pa$$w0rd”,“Account for running the Marketing Web service”
   CreateUser “OrdersWebSvc”,“Pa$$w0rd”,“Account for running the Orders Web service”
   CreateUser “ProfilesWebSvc”,“Pa$$w0rd”,“Account for running the Profiles Web service”
   CreateUser “RunTimeUser”,“Pa$$w0rd”,“IIS account for accessing a Commerce Server site or application”

   MsgBox “Complete!”

End Sub

‘ Create the local user
Sub CreateUser(userName, password, description)

   ’ Check to see if the user exists; if so, then skip
   If NOT CheckIfUserExists(userName) Then
      Set objComputer = GetObject(“WinNT://” & strComputer & “”)
      Set objUser = objComputer.Create(“user”, userName)

      objUser.SetPassword password
      objUser.FullName = userName
      objUser.Description = description
      objUser.Put “UserFlags”, 65600 ‘ Sets Password Never Expires to TRUE
      ’ and sets User Can’t Change Password to TRUE
      objUser.SetInfo
   Else
      MsgBox userName & ” already exists!”
   End If

End Sub

‘ Check to see if user exists
Function CheckIfUserExists(userName)

   Set objComputer = GetObject(“WinNT://” & strComputer & “”)
   objComputer.Filter = Array(“user”)
   intFound = 0

   For Each User In objComputer
      If lcase(User.Name) = lcase(userName) Then
         intFound =
      End If 
   Next

   If intFound = 1 Then
      CheckIfUserExists = True
   Else
      CheckIfUserExists = False
   End If

End Function


And there you have it!



CreateCS2007LocalUsers.vbs (2.46 KB)


I hope someone else finds this useful!

Comments (4)

  • Thank you very, very much! I really needed this!

  • I am very glad it helped! Best regards!

  • Hi,

    Thanks for the script it works fine, but can you please provide me account expiry function in the same script please?
    I am having following script for setting expiry date for the created account, but don’t know to merge both the scripts, as i am not a software guy, so can you please help me out in this.

    SCRIPT : for Setting an Expiration Date for a Local User Account

    Binds to a local user account (kenmyer) on a computer named atl-win2k-01, and configures the account to expire on March 1, 2003.

    strComputer = "atl-win2k-01"
    Set objUser = GetObject("WinNT:// " & strComputer & "/kenmyer ")
    objUser.AccountExpirationDate = #03/01/2003#
    objUser.SetInfo

    please mail me the solution on mayurgharat@gmail.com.

    Thanks A LOT,
    Mayur Gharat

  • I think this code is awesome also. It does what a lot of scripts do not. I also have one question though. When I check the accounts it does not add them to local groups. I have tried different variations of the code but none of them add the account to local groups. All the ones I have found require you to specify the computer name.

    Is there some way to make this add the accounts to a specific group?

    Thanks again Wade.

    Kevin

Do you have anything to say?