Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Create local user from sysprep

Reply
 
Old 08-11-2009   #1 (permalink)
Jake


 
 

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
Old 08-12-2009   #2 (permalink)
Tim Munro


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46