The following are bits and pieces of VBscripts I use with RunOnceEx to do this. You can implement them as you see fit.
Script 1:
CODE
Option Explicit
Dim ws, fs, wn, sysdrv, compname, colDrives, objDrive, strOEM
Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set wn=WScript.CreateObject("WScript.Network")
sysdrv = ws.ExpandEnvironmentStrings ("%SYSTEMDRIVE%")
compname = ws.ExpandEnvironmentStrings ("%COMPUTERNAME%")
Set colDrives = fs.Drives
For Each objDrive in colDrives
If fs.FileExists(objDrive.DriveLetter & ":\WIN51") Then strOEM = objDrive.DriveLetter & ":\OEM"
Next
'** Subroutine; Set the RunOnceEx key with values
Sub SetROE
Dim strKeyPath
strKeyPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\"
ws.RegWrite strKeyPath & "TITLE", "System Optimization", "REG_SZ"
ws.RegWrite strKeyPath & "080\", "Final Hard Disk Defragmentation", "REG_SZ"
ws.RegWrite strKeyPath & "080\1", strOEM & "\080_FinalDefrag.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "090\", "Setting User Accounts", "REG_SZ"
ws.RegWrite strKeyPath & "090\1", strOEM & "\090_ConfigAccounts.vbs", "REG_SZ"
End Sub
'** Subroutine; Create and configure a temp Administrator account
Sub TempAdmin
Dim strComputer, strPath, objComp, objUser, objGroup
strComputer=wn.ComputerName
strPath=("WinNT://" & strComputer)
Set objComp=GetObject(strPath)
Set objUser=objComp.Create("user", "TempAdministrator")
Set objGroup=objComp.GetObject("group","Administrators")
objUser.SetPassword "password"
objUser.FullName=""
objUser.SetInfo
objGroup.Add objUser.AdsPath
End Sub
'** Subroutine; Set AutoLogin for the next reboot
Sub SetAutoLogin
Dim strKeyPath
strKeyPath = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\"
ws.RegWrite strKeyPath & "AutoAdminLogon", "1", "REG_SZ"
ws.RegWrite strKeyPath & "AutoLogonCount", "1", "REG_SZ"
ws.RegWrite strKeyPath & "DefaultPassword", "password", "REG_SZ"
ws.RegWrite strKeyPath & "DefaultUserName", "TempAdministrator", "REG_SZ"
End Sub
'** Run Tasks
SetROE
TempAdmin
SetAutoLogin
ws.Run("""%PROGRAMFILES%\Utilities\ntregopt.exe"" silent /noprogresswindow /reboot"),0, False
What this script does is create a temporary Administrator user (TempAdministrator) and set the auto logon information for that newly created admin user. It also sets the RunOnceEx settings for the next boot. You must reboot in order to copy the ntuser.dat file of the currently logged in user. I happen to use NTRegOpt, a registry optimizer for initiating the reboot.
Here is the next script 090_ConfigAccounts.vbs, which is set for RunOnceEx in the script above:
CODE
Option Explicit
On Error Resume Next
Dim ws, fs, wn, objReg, sysdrv, strComputer, strPath, objComp, colDrives, objDrive, strOEM
Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set wn = WScript.CreateObject("WScript.Network")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\default:StdRegProv")
sysdrv = ws.ExpandEnvironmentStrings ("%SYSTEMDRIVE%")
strComputer = wn.ComputerName
strPath = ("WinNT://" & strComputer)
Set objComp = GetObject(strPath)
Set colDrives = fs.Drives
For Each objDrive in colDrives
If fs.FileExists(objDrive.DriveLetter & ":\WIN51") Then strOEM = objDrive.DriveLetter & ":\OEM"
Next
'** Subroutine; Process the built-in Administrator account
Sub ProcessAdmin
Dim objUser1, objUser2, objGroup1, objGroup2, flag
Set objUser1=objComp.GetObject("user","Administrator")
Set objGroup1=objComp.GetObject("group","Debugger Users")
Set objGroup2=objComp.GetObject("group","Guests")
objGroup1.Remove objUser1.AdsPath
objGroup2.Add objUser1.AdsPath
objUser1.SetPassword "password1"
Set objUser2=objComp.MoveHere(objUser1.ADsPath,"Jerry")
objUser2.Description=""
objUser2.SetInfo
If objUser2.AccountDisabled="False" Then flag=objUser2.Get("UserFlags")+2
objUser2.Put "UserFlags", flag
objUser2.SetInfo
End Sub
'** Subroutine; Process the built-in Guest account
Sub ProcessGuest
Dim objUser1, objUser2
Set objUser1=objComp.GetObject("user","Guest")
objUser1.SetPassword "password2"
Set objUser2=objComp.MoveHere(objUser1.AdsPath,"Kramer")
objUser2.Description=""
objUser2.SetInfo
End Sub
'** Subroutine; Create and configure a fake Administrator account
Sub FakeAdmin
Dim objUser, objGroup, flag
Set objUser=objComp.Create("user", "Administrator")
Set objGroup=objComp.GetObject("group","Guests")
objUser.SetPassword "password4"
objUser.Description="Built-in account for administering the computer/domain"
objUser.FullName=""
objUser.SetInfo
objGroup.Add objUser.AdsPath
If objUser.AccountDisabled="False" Then flag=objUser.Get("UserFlags")+2
objUser.Put "UserFlags", flag
objUser.SetInfo
End Sub
'** Run Tasks
ProcessAdmin
ProcessGuest
FakeAdmin
fs.CopyFile (sysdrv & "\Documents and Settings\Administrator\ntuser.dat"), (sysdrv & "\Documents and Settings\Default User\ntuser.dat"),True
If fs.FolderExists(sysdrv & "\Documents and Settings\Administrator") Then fs.DeleteFolder(sysdrv & "\Documents and Settings\Administrator"), True
objComp.Delete "user", "Administrator"
objComp.Delete "user", "ASPNET"
objComp.Delete "user", "HelpAssistant"
objComp.Delete "user", "SUPPORT_388945a0"
objComp.Delete "user", "TempAdministrator"
If fs.FileExists(strOEM & "\090_NameSettings.hta") Then ws.Run (strOEM & "\090_NameSettings.hta"),1,True
WScript.Sleep(2000)
ws.Run("""%PROGRAMFILES%\Utilities\ntregopt.exe"" silent /noprogresswindow /reboot"),0, False
This script does a little management of the builtin accounts for better security. Of interest to this thread is towards the bottom of the script, where the ntuser.dat file is copied over to the Default User profile. Also note that at this point the computer is logged in under the credentials of TempAdministrator, but you can still delete the user account from the computer prior to rebooting. Right at the end, I run an hypertext application that I made (my very first one) that brings up a dialog for the user to specify the name of the computer, the name and password for an Administrative user and the name and password for a Restricted user. I'll include it in case anyone wants to check it out and use it.