自动加域脚本 /改计算机名/加域/加用户到本地管理员组
一共有三个脚本。第一个是改计算机名然后重启。第二个是加域和加用户账号到本地管理员组。第三个是删除痕迹和重启
这里计算机名的命名方法是:cis+ domainaccount+00 (site 简写+用户账号+用户第几台计算机,可以根据需要调整计算机名
你只需要运行第一个脚本 changename.vbs 然后会弹出一个窗口叫你输入计算机名。余下的就有脚本帮你完成了。
changename.vbs
'**************************************************************************************************************
'Description: Change computer name reboot the system and auto login system with administrator
'
'author: [email]Bo.zhang@lsi.com[/email]
'time : 08/30/2010
'
'**************************************************************************************************************
'Option Explicit
'On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer
Dim newComputerName
Dim strKeyPath
Dim strKeyPathTCPIP
Dim objReg
Dim objSysInfo
'Dim computerPath
'Dim arrDirectoryLocation()
'Dim i
'Dim strLocation
'Dim ouPath
strComputer = "."
strKeyPath = "SYSTEM/CurrentControlSet/Control/ComputerName/"
strKeyPathTCPIP = "SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/"
Set objReg = GetObject("WinMgmts:{impersonationLevel=Impersonate}!//" & _
strComputer &"/root/default:StdRegProv")
Set ShellObj = WScript.CreateObject("WScript.Shell")
'*****************************************************make the script run one when system start
ShellObj.RegWrite "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/RunOnce/addtodomain", "c:/windows/addtodomain.vbs"
Set FSO = WScript.CreateObject("Scripting.FilesystemObject")
'****************************** copy files to local
FSO.CopyFile "addtodomain.vbs", "c:/windows/addtodomain.vbs"
Set NetObj = WScript.CreateObject("WScript.Network")
WinDir = FSO.GetSpecialFolder(0)
SysDir = FSO.GetSpecialFolder(1)
On Error Resume Next
WinPass="HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon/"
'Call changeRegInfo(newComputerName)
'Call AutoLogon
'Call shutdown
'**************************************FUNCTIONS************************************************************************
'Function changeRegInfo(newComputerName)
newComputerName = InputBox ("inpute your computer name")
objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPathTCP,"Hostname"
objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPathTCP,"NV Hostname"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "ComputerName/",_
"ComputerName",UCase(newComputerName)
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "ActiveComputerName/",_
"ComputerName",UCase(newComputerName)
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPathTCPIP,"Hostname",LCase(newComputerName)
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPathTCPIP,"NV Hostname",LCase(newComputerName)
'End Function
'*************************************************************************************************************************
Dim objFso
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
objFso.CopyFile "addtodomain.*", "c:/windows"
''*************************************************************************************************************************
'Function AutoLogon
Dim sUser, sPass
' sUser = InputBox("Enter Username to Autologin")
' sPass = InputBox("Enter Password")
sUser = "administrator"
sPass = "LSI1AdMiN"
ShellObj.RegWrite WinPass & "AutoAdminLogon","1","REG_SZ"
ShellObj.RegWrite WinPass & "DefaultPassword", sPass, "REG_SZ"
ShellObj.RegWrite WinPass & "DefaultUserName", sUser,"REG_SZ"
'Set ShellObj = WScript.CreateObject("WScript.Shell")
' shellobj.Run "command.com /k"&"shutdown -r -t 0"
' WScript.QUIT "command.com /k"&
'End Function
'*************************************************************************************************************************
Set ShellObj = WScript.CreateObject("WScript.Shell")
shellobj.Run "shutdown -r -t 0"
'*************************************************************************************************************************
第二个脚本 你需要在红色部分根据需要添加你公司的域和你的加入域时用的账号和密码
'*************************************************************************************************
'Description: Join domian and add user account to local administrators group and reboot the system
' author:Bo.zhang@lsi.com
' Date:08/30/2010
'**************************************************************************************************
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "[color=Red]yourdomain[/color]"
strPassword = "[color=Red]********[/color]"
strUser = "[color=Red]your account [/color]"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!//" & _
strComputer & "/root/cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "/" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)
'**********************************************************************************************
' add useraccount to local admin group
'***********************************************************************************************
Dim useraccount
Set net = WScript.CreateObject("WScript.Network")
local = net.ComputerName
useraccount =Left(local,Len(local)-2)
useraccount=Right(useraccount,Len(useraccount)-3)
MsgBox useraccount
DomainName = "lsi"
set group = GetObject("WinNT://"& local &"/Administrators")
on error resume next
group.Add "WinNT://"& DomainName &"/"& UserAccount &""
CheckError
sub CheckError
if not err.number=0 then
set ole = CreateObject("ole.err")
MsgBox ole.oleError(err.Number), vbCritical
err.clear
else
MsgBox "Done."
end if
end sub
'**********************************************************************************************
'disable admin auto logon and reboot the system the system
'**********************************************************************************************
WinPass="HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon/"
Set ShellObj = WScript.CreateObject("WScript.Shell")
ShellObj.RegWrite WinPass & "AutoAdminLogon","0","REG_SZ"
'**********************************************************************************************
'delete teh addtodomain in c:/windows
'**********************************************************************************************
ShellObj.Run ("""c:/windows/addtodomain.bat""") ', 0, True
'shellobj.Run "shutdown -r -t 0"
第三部分是 重启删去在用户计算机里的脚本
'**************************************************************************************************************
addtodomain.bat (起这个名字跟第二个相同时应为我再用vbs copy 时我图省事,把addtodomain.* 都拷贝到本地。自然addtodomain.bat 也copy 过来的)
(Dim objFso
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
objFso.CopyFile "addtodomain.*", "c:/windows" )
'**************************************************************************************************************
del /q c:/windows/addtodomain.vbs
shutdown -r -t 0