26
2024
01
01:58:17

AutoIT - 加域工具



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

制作了一款加域工具,可以实现的功能如下,源代码供参考:

  • 调用的是AD.au3

  • 根据地域不同,生成不同的计算机名前缀

  • 根据地域不同,分配到不同的OU

  • 在生成的计算机名后增加2位数字,且在域内进行查找,确保没有重复的计算机名

  • 将计算机加域,且更换计算机名

源码:

#include <AD.au3>
#include <Network.au3>
#include <WinAPIFiles.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $sComputerName = @YEAR & @MON & @MDAY
Global $sUser = "***"
Global $sPassd = "***"
Global $sDomain = "***"
Global $sDNSDomain = 'DC=***'
Global $sConfig = 'CN=Configuration,DC=***'
Global $dDNSSuffix[1] = [$sDomain]

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("计算机加域工具 1.0", 280, 180)
GUICtrlCreateGroup("PC所在区域", 24, 16, 97, 145)
$Radio1 = GUICtrlCreateRadio("北京", 50, 40, 50, 17)
$Radio2 = GUICtrlCreateRadio("廊坊", 50, 64, 50, 17)
$Radio3 = GUICtrlCreateRadio("长沙", 50, 88, 50, 17)
$Radio4 = GUICtrlCreateRadio("苏州", 50, 112, 50, 17)
$Radio5 = GUICtrlCreateRadio("远程", 50, 136, 50, 17)
$Input1 = GUICtrlCreateInput("", 136, 56, 121, 21)
$Label1 = GUICtrlCreateLabel("计算机名", 136, 32, 52, 17)
$Button1 = GUICtrlCreateButton("确定", 160, 120, 75, 25)
Dim $Form1_AccelTable[1][2] = [["{ENTER}", $Button1]]
GUISetAccelerators($Form1_AccelTable)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Radio1
GUICtrlSetData($Input1, 'PC' & $sComputerName)
GUICtrlSetState($Button1, $GUI_ENABLE)
$sOU = 'OU=Beijing Computers,DC=***,DC=co'
Case $Radio2
GUICtrlSetData($Input1, 'LF' & $sComputerName)
GUICtrlSetState($Button1, $GUI_ENABLE)
$sOU = 'OU=Langfang Computers,DC=***,DC=co'
Case $Radio3
GUICtrlSetData($Input1, 'CS' & $sComputerName)
GUICtrlSetState($Button1, $GUI_ENABLE)
$sOU = 'OU=Changsha Computers,DC=***,DC=co'
Case $Radio4
GUICtrlSetData($Input1, 'SZ' & $sComputerName)
GUICtrlSetState($Button1, $GUI_ENABLE)
$sOU = 'OU=Suzhou Computers,DC=***,DC=co'
Case $Radio5
GUICtrlSetData($Input1, 'RS' & $sComputerName)
GUICtrlSetState($Button1, $GUI_ENABLE)
$sOU = 'OU=Remote Computers,DC=***,DC=co'
Case $Button1
GUICtrlSetState($Button1, $GUI_DISABLE)
$sComputerName = _ComputerNameCheck(GUICtrlRead($Input1))
GUICtrlSetData($Input1, $sComputerName)
GUICtrlSetState($Input1, $GUI_DISABLE)
$Check = _JoinDomain($sComputerName, $sOU)
SplashTextOn('提示', '计算机' & $sComputerName & '已完成加域,系统将立即重启!', 400, 50)
Sleep(5000)
SplashOff()
Shutdown(2)
Exit
EndSwitch
WEnd

Func _ComputerNameCheck($Name)
$i = 0
_AD_Open($sUser, $sPassd, $sDNSDomain, $sDomain, $sConfig)
Do
$i = $i + 1
$CName = $Name & '0' & String($i)
$Check = _AD_ObjectExists($CName & '$')
Until $Check = 0
Return $CName
EndFunc   ;==>_ComputerNameCheck

Func _JoinDomain($Name, $OU)
_SetDNSSuffixSearchOrder($dDNSSuffix) ; Add DNS suffix

$i = _AD_JoinDomain(@ComputerName, '', '', $OU, 3, $Name)
If $i = 0 Then
MsgBox(16, '加域失败!', '错误编码' & @error & '-' & @extended)
Exit
EndIf
_AD_Close()
EndFunc   ;==>_JoinDomain



https://blog.csdn.net/cloudtuo/article/details/81182753



本文链接:https://hqyman.cn/post/4931.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: