#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 ThenProgressSet(95,"正在将目标用户加入到管理员组")If $asuser_r="" ThenMsgBox(0,"错误","目标用户名不能为空!")ProgressOff()ContinueLoopElsejoinadmin($asuser_r)EndIfProgressSet(100,"","完成")Sleep(3000)ProgressOff()popup("重起","加域成功,计算机将在10秒后重起",10)Shutdown(6)ElseProgressOff()WinSetState("加域-XX","",@SW_SHOW)ContinueLoopEndIfExitCase $msg=$cancel Or $msg=$GUI_EVENT_CLOSEExitLoopEndSelect
WEnd
Func Ping_domain($domain) ;判断能否连接到域If Ping($domain) ThenReturn TrueElseReturn FalseEndIf
EndFunc
Func getOldCName();获取旧的电脑名称$obj=ObjCreate("WScript.Network")Return $obj.ComputerName
EndFunc
Func 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 FalseEndIfNext
EndFunc
Func 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 FalseEndIf
EndFunc
Func 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 FalseEndIfEndIfEndFunc
Func 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)ExitLoopEndIfWEnd
EndFunc
Func timespan($gui,$text,$time)While $time>0GUICtrlSetData($gui,$text&" "&$time)Sleep(1000)$time=$time-1WEnd
EndFuncFunc joinadmin($asuser)RunWait(@ComSpec&' /c net localgroup administrators aspire\'&$asuser&' /add')EndFunc

转载于:https://www.cnblogs.com/sunchao1984/p/5105142.html

使用autoit实现自动加域相关推荐

  1. [转]WinXP、Win7脚本自动加域及用户资料迁移

    原文地址 http://shubao.blog.51cto.com/401810/710102 WinXP.Win7脚本自动加域及用户资料迁移 最近公司要上AD域项目,所有的用户全部从工作组环境切换到 ...

  2. WinXP、Win7脚本自动加域及用户资料迁移(一)

    WinXP.Win7脚本自动加域及用户资料迁移(一) 最近公司要上AD域项目,所有的用户全部从工作组环境切换到域环境,本地账号迁移到域账号.因客户端比较多,仔细研究了一下微软的加域和用户迁移工具,结合 ...

  3. 自动加域脚本,bat和vbs配合使用,使加域操作更简单

    我的实验:编写自动加域脚本(总结) 1.自动加域脚本的目的. A.减少重复繁杂的必要操作,提高工作效率. B.使加域操作更简单,更有乐趣. 2.自动加域的实现方式,分为三个步骤. A.使用bat和vb ...

  4. 禁止更改计算机名_计算机改名、加域脚本集合

    windows计算机改名.改密码.设置ip.加域脚本集合 今天和大家分享一下,如何将前面的改名加域整合在一起,根据选择执行对应的命令. 新建txt文档,输入一下代码,另存为"自动加域脚本.b ...

  5. Windows Server:客户端脱机加域

    1.使用场景: 1)一个组织可能需要在数据中心部署许多虚拟机.脱机加域使虚拟机在安装操作系统后,最初启动时就可以直接加域,而无需额外重新启动.这可以显著减少大规模虚拟机部署时所需的总时间. 2)在分站 ...

  6. jquery仿邮箱文本输入框自动加载邮箱后缀

    jquery仿邮箱文本输入框自动加载邮箱后缀 在像百度这样的网站注册时,你会看到输入邮箱会出现自动给用户输入补全主流邮箱.这种对于增加用户体验的小例子已司空见惯.正好看到人家写的这种js功能.还挺不错 ...

  7. 2008 R2 辅域安装和卸载(加域、退域及组策略的测试)

    一.辅域安装 1.运行--dcpromo 2.向现有域添加域控制器 3.输入主域域名fdwxyjy.com 4.选择站点(默认即可,此处wuxi是因为在AD中重命名了) 5.辅域安装完后重启,在主域上 ...

  8. Windows Server 2016-Netdom Join加域并指定OU (一)

    前边我们提到了客户端如何通过图形化.netdom .Powershell方式加域,这里我们简单补充下生产环境中如何通过有权限的用户账号加域并指定对应的OU,以防止域策略下发对部分生产服务器权限等内容进 ...

  9. 基于IP子网将加域的电脑移动到不同的OU

    在域环境下,电脑在加域后,默认所有电脑都会放在computers下面.在单域多站点的域架构中,都会针对各站点配置不同的组策略进行系统更新.软件分发等策略,这样就需要将电脑分别移动到不同站点所对应的OU ...

最新文章

  1. 多项物联网技术评为即将改变世界的革新技术
  2. 百度地图与谷歌地球的偏差调整
  3. 特种部队【动态规划】
  4. 人际交往的“三有三避”
  5. 【转】蓝牙技术及其系统原理
  6. c语言 at指令,学渣求指教,如何识别字符串中的AT命令并逐个输出,求程序!!!...
  7. leetcode 40. 组合总和 II 思考分析
  8. DevOps是什么意思
  9. dalvik虚拟机简单介绍
  10. 360智能工程中心期待你的加入
  11. 【数据结构----笔记2】查找算法之【哈希查找或散列查找】
  12. Python自省函数getattr的用法
  13. 刷题总结——Human Gene Functions(hdu1080)
  14. 时态数据库的应用介绍(1)
  15. 力扣-746. 使用最小花费爬楼梯
  16. 雷达散射截面(RCS)
  17. solidworks 2016 crack
  18. 定时任务的多种实现——xxl-job
  19. 跳跃表(SkipList)
  20. OSPF-LSA详解

热门文章

  1. uva10026-鞋匠的难题
  2. [转]Android截屏及图片解析
  3. Classic ASP 系列(3) Application 对象
  4. Hive文件数创建过多的问题
  5. JDK1.8 IdentityHashMap
  6. Verilog实现AXI4-Lite源代码
  7. mongodb mysql数据类型_mongodb中数据类型的坑
  8. java 判断当前时间是否为节假日_浅谈Java8日期时间处理
  9. 红外测距模块 51单片机_[51单片机] HC-SR04超声波测距仪
  10. STM32基础定时器详解