#Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****#AutoIt3Wrapper_Icon=C:\Users\helpdesk07\Desktop\autoit脚本\fuwuqi.ico#AutoIt3Wrapper_OutFile_x64=成品脚本\jiayuv2.exe#AutoIt3Wrapper_Res_Comment=不重起自动修改计算机名,加网域#AutoIt3Wrapper_Res_LegalCopyright=孙超 #AutoIt3Wrapper_Res_Language=2052#AutoIt3Wrapper_Res_requestedExecutionLevel=None#EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****#Region ;**** 参数创建于 ACNWrapper_GUI ****#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****#include <GUIConstants.au3>#include <GUIConstantsEx.au3>#include <EditConstants.au3>#include <ButtonConstants.au3>#include <StaticConstants.au3>#include <WindowsConstants.au3>Opt("GUICoordMode",1)Opt("TrayIconHide",1)#CS 旧代码注释$gui=GUICreate("加域-XX",300,200,300,300)$computer=GUICtrlCreateLabel("电脑名:",20,20,50)$computer_text=GUICtrlCreateInput("",75,20,200)$user=GUICtrlCreateLabel("用户名:",20,50,50)$user_text=GUICtrlCreateInput("domain\sunchao",75,50,200)$pwd=GUICtrlCreateLabel("密码:",20,80,50)$pwd_text=GUICtrlCreateInput("apassword",75,80,200,"",$ES_PASSWORD)$domain_name=GUICtrlCreateLabel("域:",20,110,50)$domain_text=GUICtrlCreateInput("www.domain.com",75,110,200)$ou=GUICtrlCreateLabel("OU:",20,140,50)$ou_text=GUICtrlCreateInput("ou=computers,dc=domain,dc=com",75,140,200)$ok=GUICtrlCreateButton("确 定",80,175,80)$cancel=GUICtrlCreateButton("取 消",195,175,80)GUISetState(@SW_SHOW)#ce#Region ### START Koda GUI section ### Form=D:\文档\au3script\加域v2.kxf$Form2 = GUICreate("加域-XX-v2.0", 494, 362, 205, 137)$computer = GUICtrlCreateLabel("电脑名", 51, 27, 48, 17)$computer_text = GUICtrlCreateInput("", 106, 25, 193, 21)$asuse = GUICtrlCreateLabel("目标用户名", 27, 65, 64, 17)$asuser_text = GUICtrlCreateInput("", 107, 62, 193, 21)$user = GUICtrlCreateLabel("工程师用户名", 17, 102, 76, 17)$user_text = GUICtrlCreateInput("", 107, 101, 193, 21)$pwd = GUICtrlCreateLabel("工程师密码", 26, 139, 64, 17)$pwd_text = GUICtrlCreateInput("", 106, 136, 193, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))$domain_name = GUICtrlCreateLabel("域", 46, 179, 16, 17)$domain_text = GUICtrlCreateInput("", 106, 176, 193, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))$ou = GUICtrlCreateLabel("OU", 44, 220, 20, 17)$ou_text = GUICtrlCreateInput("", 106, 217, 193, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))$ok = GUICtrlCreateButton("确定", 45, 276, 91, 30)$cancel = GUICtrlCreateButton("取消", 211, 276, 91, 30)GUISetState(@SW_SHOW)#EndRegion ### END Koda GUI section ###GUICtrlSetData($computer_text,getOldCName())While 1Local $msg=GUIGetMsg()Local $resultSelectCase $msg=$okLocal $computer_r=GUICtrlRead($computer_text)Local $user_r=GUICtrlRead($user_text)Local $password_r=GUICtrlRead($pwd_text)Local $domain_r=GUICtrlRead($domain_text)Local $ou_r=GUICtrlRead($ou_text) Local $asuser_r=GUICtrlRead($asuser_text)WinSetState("加域-XX","",@SW_HIDE)ProgressOn("加域-XX","检查必要文件是否存在","","400","350",2)If Not(FileExists(@SystemDir&"\dsquery.exe") And FileExists(@SystemDir&"\netdom.exe") And FileExists(@SystemDir&"\dsquery.dll")) ThenMsgBox(4096,"提示","请复制dsquery.exe、netdom.exe、dsquery.dll到system32文件夹")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(10,"","检查是否填写完整")If $computer_r="" Or $user_r="" Or $password_r="" Or $domain_r="" ThenMsgBox(4096,"提示","请填写完整!")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(20,"","检查计算机名是否符合规则")If Not nameIsRorE($computer_r) ThenMsgBox(4096,"提示","计算机名不符合规则,只能由字母数字和连字符组成,不能超过15个字符,且不能全为数字!")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(30,"","建立到网域的连接")If Not Ping_domain($domain_r) ThenMsgBox(4096,"提示","不能联系到域"&$domain_r&"请检查网络配置!")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(40,"","检查是否已经加入网域")If Not isGorD() ThenMsgBox(4096,"提示","你已经是域成员!")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(50,"","验证用户名和密码是否正确")If Not E_UandP($domain_r,$user_r,$password_r) ThenMsgBox(4096,"提示","用户名或密码错误!")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(60,"","检查计算机名是否已经在域中使用")If userExists($computer_r,$domain_r,$user_r,$password_r) ThenMsgBox(4096,"提示","该计算机名已经在域中使用!")ProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfProgressSet(70,"","正在加入网域")If StringUpper($computer_r)==StringUpper(getOldCName()) Then$alert=MsgBox(1,"提示","你没有修改计算机名,确认以当前计算机名加入网域吗?")If $alert>1 ThenProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfElseProgressSet(80,"正在修改计算机名")rename($computer_r)EndIfProgressSet(90,"正在加入网域")$result=join($computer_r,$domain_r,$user_r,$password_r,$ou_r)If $result=1 Then ProgressSet(95,"正在将目标用户加入到管理员组") If $asuser_r="" Then MsgBox(0,"错误","目标用户名不能为空!") ProgressOff() ContinueLoop Else joinadmin($asuser_r) EndIf ProgressSet(100,"","完成")Sleep(3000)ProgressOff()popup("重起","加域成功,计算机将在10秒后重起",10)Shutdown(6)ElseProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfExitCase $msg=$cancel Or $msg=$GUI_EVENT_CLOSEExitLoopEndSelectWEndFunc Ping_domain($domain) ;判断能否连接到域If Ping($domain) ThenReturn TrueElseReturn FalseEndIfEndFuncFunc getOldCName();获取旧的电脑名称$obj=ObjCreate("WScript.Network")Return $obj.ComputerNameEndFuncFunc isGorD() ;判断是否已经加入网域$strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")$collitems=$objWMIService.ExecQuery("Select * From Win32_ComputerSystem")For $colitem In $collitemsLocal $rule=$colitem.DomainRoleIf $rule=0 ThenReturn TrueElseReturn FalseEndIfNextEndFuncFunc userExists($computer_name,$domainname,$username,$password) ;判断域中是否已经存在相同的电脑名Local $path=@SystemDir&"\comp.txt"If FileExists($path) ThenFileDelete($path)EndIfRunWait(@ComSpec&" /c dsquery computer -name "&$computer_name&" -d "&$domainname&" -u "&$username&" -p "&$password&" > "&$path,"",@SW_HIDE)If FileGetSize($path)>0 ThenReturn TrueElseReturn FalseEndIfEndFuncFunc rename($name) ;重命名电脑名RegWrite("HKLM\system\currentcontrolset\control\computername\computername","computername","REG_SZ",$name)RegWrite("HKLM\system\currentcontrolset\control\computername\ActiveComputerName","computername","REG_SZ",$name)RegWrite("HKLM\system\currentcontrolset\services\tcpip\parameters","nv hostname","REG_SZ",$name)RegWrite("HKLM\system\currentcontrolset\services\tcpip\parameters","hostname","REG_SZ",$name)EndFuncFunc join($computer_name,$domain,$user,$pwd,$ou) ;加域Local $temp=@SystemDir&"\join.txt"Local $strLocal $resultIf $ou="" Then$str=" /c netdom join "&$computer_name&" /domain:"&$domain&" /userD:"&$user&" /passwordd:"&$pwd &" > "&$tempElse$str=" /c netdom join "&$computer_name&" /domain:"&$domain&" /ou:"&$ou&" /userD:"&$user&" /passwordd:"&$pwd &" > "&$tempEndIfIf MsgBox(1,"确认","你确认加入网域 "&$domain &" ?")=1 ThenIf FileExists($temp) ThenFileDelete($temp)EndIfRunWait(@ComSpec&$str,"",@SW_HIDE)If FileExists($temp) Then$str=FileReadLine($temp)If StringLower($str)=="the command completed successfully." Then$result=1Else$result=2MsgBox(4096,"提示",$str)EndIfEndIfElse$result=3EndIfReturn $resultEndFuncFunc nameIsRorE($computername) ;判断计算机名是否符合规则$result=StringRegExp($computername,'^[a-zA-Z0-9-]{1,15}$')$result1=StringRegExp($computername,'^\d{1,15}$')If $result==1 And $result1==0 ThenReturn TrueElseReturn FalseEndIfEndFuncFunc E_UandP($domain,$user,$pwd) ;判断用户名和密码是否正确Local $path=@SystemDir&"\net.txt"If FileExists($path) ThenFileDelete($path)EndIfRunWait(@ComSpec&' /c net use * /del /y',"",@SW_HIDE)RunWait(@ComSpec&" /c net use \\"& $domain & "\ipc$ /user:"&$user&" "&$pwd&" > " &$path,"",@SW_HIDE)If FileExists($path) ThenIf FileGetSize($path)>0 ThenReturn TrueElseReturn FalseEndIfEndIfEndFuncFunc popup($title,$text,$second)Local $gui=GUICreate($title,240,60)GUISetState(@SW_SHOW)$tishi=GUICtrlCreateLabel("",10,20,200,15)While 1If $second>0 Thentimespan($tishi,$text,$second)ExitLoopEndIfWEndEndFuncFunc timespan($gui,$text,$time)While $time>0GUICtrlSetData($gui,$text&" "&$time)Sleep(1000)$time=$time-1WEndEndFuncFunc joinadmin($asuser) RunWait(@ComSpec&' /c net localgroup administrators aspire\'&$asuser&' /add')EndFunc
转载于:https://www.cnblogs.com/sunchao1984/p/5105142.html
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/4933.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
打赏
微信支付宝扫一扫,打赏作者吧~
休息一下~~