AutoIT - 加域工具

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

  • 调用的是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

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
客户加入域之---Profwiz的使用 要发挥微软活动目录的强大功能的前提工作就是:把公司里的所有客户计算机加入域。单纯的入域操作虽然简单,可后续的权限修改、User Profile迁移、频繁的重启计算机等工作可能会让你捣鼓一整天才把不够10台计算机加入域!今天给大家推荐一款微软合作伙伴开发的免费工具:Profwiz,使用Profwiz可以一次性的完成3项工作:把计算机入域、本地用户Profile迁移到域用户下和赋予域用户本地管理员权限。 1.右击任务栏右下角的本地连接或者在开始—控制面板打开网络和共享中心在,点击本地连接。 2.点击本地连接的属性—TCP/IPV4—设置首选DNS:192.168.18.254 备用DNS服务器: 202.96.134.133 3.修改计算机名字,如santom,计算机名修改完毕后必须重启电脑。 把Profwiz.exe下载,无需注册,无需安装,双击打开即可使用。 1) 双击打开Profwiz.exe点击下一步; 2) 输入加入域的域名(risecomm.it)和将来使用的域帐户,这里测试账号 (santom),记得勾选Join Domain和Set as default logon,点击下一步; 3) 选择要迁移给域用户的用户配置文件(加域前账户),点击下一步; 4) 在弹出的窗口中输入分配的域账户和密码,点击OK即开始工作; PS:这里的时间是由加域之前桌面的文件大小决定 5)完成之后,重启一次计算机并使用域用户登陆,你就会发现计算机已经加入到域,相应的User Profile已经迁移到域用户下,而且,域用户已经加入到本地管理员组! 已经验证测试环境:XP_32位、Win7_32、Win7_64
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值