![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Quote: > 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| create Ad user on local machine | PowerShell | |||
| Sysprep Create Reboot Loop | Vista installation & setup | |||
| Windows Vista problem with local user account after sysprep Image | Vista installation & setup | |||
| User creation during Sysprep | Vista installation & setup | |||
| prevent sysprep from adding a new user | Vista General | |||