Windows Vista Forums

Create local user from sysprep

  1. #1


    Jake Guest

    Create local user from sysprep

    Hi,

    For some XP Home Edition computers being cloned and 'sysprepped' I need
    that sysprep runs a script that requests a username and password from
    the user and use this information to create a new local user with
    administrative rights. In addition the script should rename the
    computer object to 'PC-' + username$ where username$ is the username
    entered in the script.

    The script should have moderate error checking, denying acceptance of a
    blank username or password etc. Also it should display a success or
    failure message upon completion.

    I have managed to glue together something below. However apparently XP
    Home has simpler user accounts than XP Pro so the 'set objGroup'
    statement below fails on unknown group name. How do I do this properly
    in an XP Home environment?

    Thanks a lot for comments on this (and on other possible un-elegant
    statements below :-)

    regards



    jake

    Option Explicit
    ' On Error Resume Next

    Dim objComputer, objGroup, objUser, objWSHNetwork, strComputerName,
    strNewComputerName, strFullName, strPassword, strUserName,
    objWMIService, colComputers

    Set objWSHNetwork = WScript.CreateObject("WScript.Network")
    strComputerName = objWSHNetwork.ComputerName
    Set objComputer = GetObject("WinNT://" & strComputerName)

    Set objGroup = GetObject("WinNT://" & strComputerName & "/Administrators")

    strUserName = InputBox("Please type the given username:", "Enter your
    username")
    strFullName = InputBox("Please type your real name:", "Enter your real
    name")
    strPassword = InputBox("Please enter your given password:", "Enter your
    password")

    strNewComputerName = "PC-" & strComputerName

    Set objUser = objComputer.Create("User", strUserName)
    objUser.SetPassword strPassword
    objUser.FullName = strFullName
    objUser.SetInfo
    objGroup.Add "WinNT://" & strComputerName & "/" & strUserName
    objUser.SetInfo

    Set objWMIService = GetObject("winmgmts:" &
    "{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
    Set colComputers = objWMIService.ExecQuery ("Select * from
    Win32_ComputerSystem")
    For Each objComputer in colComputers
    err = objComputer.Rename (strNewComputerName)
    Next

    MsgBox "Completed renaming computer and adding user " & strUserName &
    ".", vbInformation, "Execution completed"

      My System SpecsSystem Spec

  2. #2


    Tim Munro Guest

    Re: Create local user from sysprep

    Hi Jake,
    On the line where you Get the group object, you are not telling the
    system what type of object to get.

    Set objGroup = GetObject("WinNT://" & strComputerName & "/Administrators")

    should read

    Set objGroup = GetObject("WinNT://" & strComputerName & "/Administrators,
    group")

    --
    Tim

    "Jake" <jake44@xxxxxx> wrote in message
    news:O$TSQpoGKHA.4316@xxxxxx

    > Hi,
    >
    > For some XP Home Edition computers being cloned and 'sysprepped' I need
    > that sysprep runs a script that requests a username and password from the
    > user and use this information to create a new local user with
    > administrative rights. In addition the script should rename the computer
    > object to 'PC-' + username$ where username$ is the username entered in the
    > script.
    >
    > The script should have moderate error checking, denying acceptance of a
    > blank username or password etc. Also it should display a success or
    > failure message upon completion.
    >
    > I have managed to glue together something below. However apparently XP
    > Home has simpler user accounts than XP Pro so the 'set objGroup' statement
    > below fails on unknown group name. How do I do this properly in an XP
    > Home environment?
    >
    > Thanks a lot for comments on this (and on other possible un-elegant
    > statements below :-)
    >
    > regards
    >
    > jake
    >
    > Option Explicit
    > ' On Error Resume Next
    >
    > Dim objComputer, objGroup, objUser, objWSHNetwork, strComputerName,
    > strNewComputerName, strFullName, strPassword, strUserName, objWMIService,
    > colComputers
    >
    > Set objWSHNetwork = WScript.CreateObject("WScript.Network")
    > strComputerName = objWSHNetwork.ComputerName
    > Set objComputer = GetObject("WinNT://" & strComputerName)
    >
    > Set objGroup = GetObject("WinNT://" & strComputerName & "/Administrators")
    >
    > strUserName = InputBox("Please type the given username:", "Enter your
    > username")
    > strFullName = InputBox("Please type your real name:", "Enter your real
    > name")
    > strPassword = InputBox("Please enter your given password:", "Enter your
    > password")
    >
    > strNewComputerName = "PC-" & strComputerName
    >
    > Set objUser = objComputer.Create("User", strUserName)
    > objUser.SetPassword strPassword
    > objUser.FullName = strFullName
    > objUser.SetInfo
    > objGroup.Add "WinNT://" & strComputerName & "/" & strUserName
    > objUser.SetInfo
    >
    > Set objWMIService = GetObject("winmgmts:" &
    > "{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
    > Set colComputers = objWMIService.ExecQuery ("Select * from
    > Win32_ComputerSystem")
    > For Each objComputer in colComputers
    > err = objComputer.Rename (strNewComputerName)
    > Next
    >
    > MsgBox "Completed renaming computer and adding user " & strUserName & ".",
    > vbInformation, "Execution completed"


      My System SpecsSystem Spec

Create local user from sysprep

Similar Threads
Thread Thread Starter Forum Replies Last Post
error create object selector to create group or user Javier VFM Server General 0 28 Oct 2009
create Ad user on local machine epiouf PowerShell 5 15 Jul 2009
Sysprep Create Reboot Loop mountnco Vista installation & setup 13 06 Feb 2009
Windows Vista problem with local user account after sysprep Image PW Vista installation & setup 0 01 Dec 2008
User creation during Sysprep MaST MaX Vista installation & setup 0 19 Oct 2008