将一个电脑加入域活动目录(Vbscript脚本语言)


下面是一个脚本语言,忘记在那个网站的了,从我的电子本上面COPY出来,共享以下,写的不错,我想大家应该看的懂里面的英文吧!我就翻译了!

Join Computer To An Active Directory Domain... ( Vbscript )

 

Script:


'===============================
'This script Changes the IP address and computer name of the Current computer (Never tested on remote computers)
'After doing so it joins the computer to the domain in a selected OU
'All the script is loged
'The Script uses the NewSID program of SysInternals and the NetDom program found in the Resource Kit of Windows
'Joining a computer to the domain works with no problem on XP Machines, on 2000 Machines you need to Join them with the NetDom command
'You can still use all the Vars you define here
'===============================

strComputer = "."
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
Const ForWriting = 2
WinDir = WshShell.ExpandEnvironmentStrings("%WINDIR%")
strLogDir = WinDir & "/system32/dllCache/"
UserProfile = WshShell.ExpandEnvironmentStrings("%userprofile%")


'=*=*=*=*=*=
'=Functions=
'=*=*=*=*=*=

Function ShutDown(strComputer)
'===============================
'This Function first closes all Office Program if open and then shuts down the computer
'It receives strComputer as the Computer Name and shuts it down
'===============================
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Process")
'===============================
' First Try to Restart the Computer with a 30 Seconds timeout
'===============================
E = objWMIService.Create("cmd /c shutdown -r -t 30 ", null, null, intProcessID)

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")
'===============================
'Close all Microsoft Office Programs
'===============================
'Outlook
'===============================
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'OUTLOOK.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
'===============================
'Excel
'===============================
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Excel.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
'===============================
'Word
'===============================
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'WinWORD.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
'===============================
'Power Point
'===============================
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'PowerPnt.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
'===============================
'Wait for 30 seconds
'===============================
wscript.sleep 30000
'===============================
'Restart the computer using WMI
'===============================
Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!//" & strComputer & "/root/cimv2")
    Set OperatingSystems = WMIService.ExecQuery("Select * From Win32_OperatingSystem")
    For Each OperatingSystem in OperatingSystems
        OperatingSystem.Reboot()
    Next
if E = 0 then
ShutDown = "OK"
end if

End Function

'=*=*=*=
'=Subs =
'=*=*=*=

Sub ChangeSID
'===============================
'This sub uses the SysInternals newSID program to generate a new SID to the computer
'This script asumes that the program is in a mapped drive (Z)
'You can use another script that maps it with Subst to a local folder..
'If your using SysPrep you dont need this Sub at all
'===============================

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Process")

Error = objWMIService.Create("cmd /c z:/newsid.exe /a" , null, null, intProcessID)
If Error = 0 Then
objFile.WriteLine "SID Changer was started with a process ID of " _
& intProcessID & "."
Wscript.echo "SID Changer is Running." & vbclrf & " This may take a few minutes, Please wait"
Else
objFile.WriteLine "SID Changer could not be started due to error " & _
Error & "."
End If

End Sub

Sub ChangeIP(Seg,IP)
'===============================
'This Sub cahnges the IP of the computer entered in the strComputer variable
'===============================
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("10.5." & Seg & "." & IP)
strSubnetMask = Array("255.255.255.0")
strGateway = Array("10.5." & Seg & ".254")
strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
ObjFile.WriteLine "The IP address has been changed."
Else
ObjFile.WriteLine "The IP address could not be changed."
End If
Next

End Sub

Sub ChangeCompName(Seg,IP)
'===============================
'This Sub Changes the Computer name according to a Constant Value and the IP address enterd
'It Changes the ComputerName key in the Registry and some other keys to do so
'===============================
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!//" &_
strComputer & "/root/default:StdRegProv")

strKeyPath = "SYSTEM/CurrentControlSet/Control/ComputerName/ComputerName"
strValueName = "ComputerName"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


strKeyPath = "SYSTEM/CurrentControlSet/Services/Tcpip/Parameters"
strValueName = "Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SYSTEM/CurrentControlSet/Services/Tcpip/Parameters"
strValueName = "NV Hostname"
strValue = "CompName" & seg & IP

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


objFile.WriteLine "Computer Name: " & strValue
'===============================
'Write the New computer name to the Log
'===============================
End Sub

Sub Join2Domain()
'===============================
'This Sub Joins the computer to the domain we enter here
'You can also designate a spesific OU for the Computer Account in the strOU Const
'This command works only on XP if you want to use it on Win2K you need to use the NetDom command that exist in windows Res Kit
'you can use the same Constants but a different syntax is required
'===============================
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
Const strOU         = "ou=oucomputers, ou=test, ou=ouprojects, dc=Domain, dc=Com"
'===============================
'Enter a valid User Name and password to join the computer to the Domain
'The Password is saved ClearText
'===============================
strDomain = "Domain"
strPassword = "ClearTextPassword"
strUser = "MyUserName"

'===============================
'This is a Check Message
'===============================
wscript.echo "Trying to join to domain " & strDomain

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!//" & _
strComputer & "/root/cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "/" & strUser, _
strOU, _
JOIN_DOMAIN + ACCT_CREATE)
'===============================
'Some Error Handling
'Any Error is written to the Log File
'===============================
If ReturnValue = 5 then
objFile.WriteLine "Access was Denied for adding the Computer to the Domain"
End If
If ReturnValue = 2224 then
objFile.WriteLine "Account exists in the Domain"
End If
if ReturnValue > 2691 then
objFile.WriteLine "The Computer was sucssefully added to the domain"
Else
objFile.WriteLine "The Computer was NOT added to the domain"
End if

End Sub

'=*=*=*=
'=Code =
'=*=*=*=
'===============================
'Here Begins our script and Calles the Subs and Functions
'First it checks if the Log file Exists, if it does it begins the process of joining it to the Domain and ending the Log file
'Else it creates the file and asks for IP address - the IP address is used to cahnge the IP of the Computer and its Name
'The Script will keep asking for the IP in the correct Order until it have it. If you want to stop it just End the Wscript process
'===============================
If objFSO.FileExists(strLogDir & "Domain Log.txt") Then
    Set objFile = objFso.OpenTextFile(strLogDir & "Domain Log.txt",ForWriting)
    Join2Domain
    objFile.Writeline "Log Ended :" & NOW
    objFile.close
Else
    fname=strLogDir & "Domain Log.txt"
    Set objFile = objFso.CreateTextFile (fname, True)

    objFile.WriteLine "Log Started : " & Now
    objFile.WriteLine
    IP = inputBox("Enter Computer IP","Enter Computer IP Between X.1 - 253")
    Do Until InStr(IP,".")
    '===============================
    'Keep Looping until the enterd text will have a " . " in it
    '===============================
        IP = inputBox("Enter Computer IP","Enter Computer IP Between X.1 - 253")
    Loop
    arrIP = Split(IP,".")
    '===============================
    'Divide the IP entered to Segment and IP address
    '===============================
    Seg = arrIP(0)
    IP = arrIP(1)
    '===============================
    'Change the IP and the Computer Name accourding to it
    '===============================
    ChangeIP Seg,IP
    ChangeCompName Seg,IP
    ChangeSID
    '===============================
    'Here we write in the Log file the Computer Booted and Close the File before the computer realy boots to k eep the file from Corrupting
    '===============================
    objFile.Writeline "Computer Booted :" & NOW
    objFile.close

End If
'===============================
'Restart the Computer !
'===============================
ShutDown strComputer

代码下载地址: https://pan.quark.cn/s/bc087ffa872a "测控电路课后习题详解"文件.pdf是一份极具价值的学术资料,其中系统地阐述了测控电路的基础理论、系统构造、核心特性及其实际应用领。 以下是对该文献的深入解读和系统梳理:1.1测控电路在测控系统中的核心功能测控电路在测控系统的整体架构中扮演着不可或缺的角色。 它承担着对传感器输出信号进行放大、滤除杂音、提取有效信息等关键任务,并且依据测量与控制的需求,执行必要的计算、处理与变换操作,最终输出能够驱动执行机构运作的指令信号。 测控电路作为测控系统中最具可塑性的部分,具备易于放大信号、转换模式、传输数据以及适应多样化应用场景的优势。 1.2决定测控电路精确度的关键要素影响测控电路精确度的核心要素包括:(1)噪声与干扰的存在;(2)失调现象与漂移效应,尤其是温度引起的漂移;(3)线性表现与保真度水平;(4)输入输出阻抗的特性影响。 在这些要素中,噪声干扰与失调漂移(含温度效应)是最为关键的因素,需要给予高度关注。 1.3测控电路的适应性表现测控电路在测控系统中展现出高度的适应性,具体表现在:* 具备选择特定信号、灵活实施各类转换以及进行信号处理与运算的能力* 实现模数转换与数模转换功能* 在直流与交流、电压与电流信号之间进行灵活转换* 在幅值、相位、频率与脉宽信号等不同参数间进行转换* 实现量程调整功能* 对信号实施多样化的处理与运算,如计算平均值、差值、峰值、绝对值,进行求导数、积分运算等,以及实现非线性环节的线性化处理、逻辑判断等操作1.4测量电路输入信号类型对电路结构设计的影响测量电路的输入信号类型对其电路结构设计产生显著影响。 依据传感器的类型差异,输入信号的形态也呈现多样性。 主要可分为...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值