What I'm looking for the VBScript to do is:
1. Checks to make sure it's a Windows XP, Windows 2003, Vista, Windows 7 OS letting the user know the OS is not supported, and exits.
2. Checks to make sure it is a 32bit OS, letting the user know that 32bit OS is only supported, and exits.
3. Set specific registry settings if the OS is XP or 2003
4. Set specific registry settings if the OS is Vista or Windows 7
5. Change the Computer name
6. Create a user account, set access to Administrator, set the password, and set the password to never expire.
6A. If the user account does exist, check the access level and set to Administrator if it's not already set, set the password, and set the password to never expire.
All this will be happening on a local system. I found some scripts but I'm not at all savvy on creating scripts. On some of the routines I've found a couple scripts.
I'm working on an install guide and these things need to be set on a Fresh OS install prior to starting the guided install. Any help would be greatly appreciated.
Is there a way to open a window for the user to inform them of what it is doing along the way?
Hopfully someone can get this straightened out, possibly have a better solution, or point me into the correct direction.
Check for OS - Only allow XP, 2003, Vista, Windows 7
================================================== ==
Code:msgbox GetOS Function GetOS() 'WMI is required for this script to function Dim strComputer, strWMIOS 'If you only want to use locally, remove the inputbox and make strComputer = "." strComputer = Inputbox("Input the name of the remote computer or hit enter for this PC.") If strComputer = "" then strComputer = "." End if Dim objWmiService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\cimv2") Dim strOsQuery : strOsQuery = "Select * from Win32_OperatingSystem" Dim colOperatingSystems : Set colOperatingSystems = objWMIService.ExecQuery(strOsQuery) Dim objOs Dim strOsVer For Each objOs in colOperatingSystems strWmios = objOs.Caption & " " & objOs.Version Next Select Case True 'Add more info to the 98 and 95 to get the specific version. i.e. 98SE 95 a,b,or c Case InStr(strWmiOS, "2000 Server") > 1 : GetOS = "2KSRV" Case InStr(strWmiOS, "2003, Standard") > 1 : GetOS = "2K3SRV" Case InStr(strWmiOS, "2003, Enterprise") > 1 : GetOS = "2K3ENTSRV" Case InStr(strWmiOS, "2000 Advanced Server") > 1 : GetOS = "2KADVSRV" Case InStr(strWmiOS, "Windows NT") > 1 : GetOS = "NT4" Case InStr(strWmiOS, "Windows 2000") > 1 : GetOS = "W2K" Case InStr(strWmiOS, "Windows XP") > 1 : GetOS = "WXP" Case Else : GetOS = "Unknown" End Select End Function
Check for 32 bit or 64bit 0nly alloec 32bit
===========================================
Code:On Error Resume Next Dim WshShell Dim OsType Set WshShell = CreateObject("WScript.Shell") OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE") If OsType = "x86" then wscript.echo "Windows 32bit system detected" elseif OsType = "AMD64" then wscript.echo "Windows 64bit system detected" end ifCode:If OsType = "x86" then wscript.echo "Windows 32bit system detected" elseif OsType = "AMD64" then wscript.echo "Windows 64bit system detected" end if
Code:info = get_OS_Bit("server1") wscript.echo info Function get_OS_Bit(strComputer) const HKEY_LOCAL_MACHINE = &H80000002 Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0" strValueName = "Identifier" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue if (instr(strValue,"x86")) then Wscript.echo "OS running on : " & strComputer & " is 32 bit." get_OS_Bit="32" elseif (instr(strValue,"64")) then get_OS_Bit="64" Wscript.echo "OS running on : " & strComputer & " is 64 bit." else get_OS_Bit="NotSure" wscript.echo "Not sure." end if End Function
Registry settings to set if XP or 2003
======================================
Code:[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] "Hidden"=dword:00000001 "HideFileExt"=dword:00000000
Registry settings to set if Vista or Windows 7
==============================================
Code:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System] "EnableLUA"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] "Hidden"=dword:00000001 "HideFileExt"=dword:00000000
Change the computer name
========================
Code:sNewName = "put new name here" Set oShell = CreateObject ("WSCript.shell" ) sCCS = "HKLM\SYSTEM\CurrentControlSet\" sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\" sCompNameRegPath = sCCS & "Control\ComputerName\" With oShell .RegDelete sTcpipParamsRegPath & "Hostname" .RegDelete sTcpipParamsRegPath & "NV Hostname" .RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName .RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName .RegWrite sTcpipParamsRegPath & "Hostname", sNewName .RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName End With ' oShell MsgBox "Computer name changed, please reboot your computer"
Create a user account, set to Administrator, and change password if user exists, Password never expires
================================================== ================================================== ===
Code:'this section creates the new username if it doesn't exist QueryForUser("username") Set objNetwork = CreateObject("Wscript.Network") strComputer = objNetwork.ComputerName Set objComputer = GetObject("WinNT://" &strComputer) Set colAccounts = GetObject("WinNT://" & strComputer & "") Set objUser = colAccounts.Create("user", "username") objUser.SetPassword "password" objUser.Put "UserFlags", 65600 ' objUser.SetInfo 'add to administrators group Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group") Set objUser = GetObject("WinNT://" & strComputer & "/username,user") objGroup.Add(objUser.ADsPath) msgbox "username was created" 'this section just changes the password if the user exists Sub QueryForUser(strUserName) Set objlocal = GetObject("WinNT://.") objlocal.Filter = Array("user") For Each User In objlocal If lcase(User.Name) = lcase(strUserName) Then strComputer = "." Set objUser = GetObject("WinNT://" & strComputer & "/username, user") objUser.SetPassword "password" objUser.SetInfo msgbox User.Name & " already exists." & vbCrLf & "The password was re-set." WScript.Quit End If Next End Sub
Code:'--------------------------------------------------------------------- ' ' The following script can be used to create a local ' user account and add it to the local Administrators ' group. To use, change the strLocalUserName to the desired ' name and change PASSWORD to password for the account. ' ' Please note, there is a limitation with the NET USER command ' where you are unable to set an account as 'never expires'. ' The bottom part of the script works arounds this. ' '--------------------------------------------------------------------- Set objShell = CreateObject ("WScript.Shell") Set Shell = Nothing on error resume next '--------------------------------------------------------------------- ' Create local account Set oWshNet = CreateObject("WScript.Network") strComputer = oWshNet.ComputerName strLocalUserName = "LocalAdmin" strGroupname = "Administrators" WScript.Sleep(900) On Error Resume Next Set objUser = GetObject("WinNT://" & strComputer & "/" & strLocalUserName & ",user") If Err.Number <> 0 Then ' User account does not exist, create it. objShell.Run "NET USER "&strLocalUserName&" PASSWORD /ADD " _ & "/ACTIVE:YES /COMMENT:""Local IT Support Account"" /FULLNAME:" _ & strLocalUserName &" /expires:never", 0, True End If On Error Resume Next ' Try again Set objUser = GetObject("WinNT://" & strComputer & "/" & strLocalUserName & ",user") If Err.Number = 0 Then ' Connect to the group Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroupname) ' Add the user account to the group ' Use error handling in case it is a member already On Error Resume Next objGroup.Add(objUser.ADsPath) WScript.sleep 600 objGroup.Add(objUser.ADsPath) ' Error -2147023518 is "The specified account name is already ' a member of the local group." End If '----------------------------------------- ' Set Account password to never expire ' This is done externally due to NET USER limitations Const ufDONT_EXPIRE_PASSWD = &H10000 objUserFlags = objUser.Get("UserFlags") if (objUserFlags And ufDONT_EXPIRE_PASSWD) = 0 then objUserFlags = objUserFlags Or ufDONT_EXPIRE_PASSWD objUser.Put "UserFlags", objUserFlags objUser.SetInfo end if
TIA....


LinkBack URL
About LinkBacks






