Use the VB script to automatically add the computer to the domain source code

Source: Internet
Author: User

Most enterprise users are added to the domain for security management. The added domain is more convenient for management. But how can new devices or users quickly join known domains? It's easy to look at the Code:

Set objshell = wscript. createobject ("wscript. shell ") strcomputer = ". "dim wshnetworkdim strcomputerset wshnetwork = wscript. createobject ("wscript. network ") strdomain = wshnetwork. userdomainif strdomain = "hupu" thenmsgbox "this client is already in the specified domain! ", 64," add domain tool "wscript. quitend ifmsgbox "determines the domain to be added. The entire process takes about 1 minute.", 64, "add domain tool" objshell. run "cmd.exe/C netsh interface IP Set DNS" "Local Connection" "static 10.10.2.116 primary", 0, trueobjshell. run "cmd.exe/C netsh interface IP add DNS" "Local Connection" "114.114.114.114", 0, trueobjshell. run "cmd.exe/c SC config LmHosts start = auto", 0, trueobjshell. run "cmd.exe/C Net start LmHosts", 0, truefunction x86orx64 () on error resume next S Trcomputer = ". "Set ob1_miservice = GetObject (" winmgmts: \ "& strcomputer &" \ Root \ cimv2 ") set colitems = ob1_miservice. execquery ("select * From win32_computersystem", 48) for each objitem in colitems if instr (objitem. systemtype, "86") <> 0 then x86orx64 = "86" elseif instr (objitem. systemtype, "64") <> 0 then x86orx64 = "64" else x86orx64 = objitem. systemtype end if next end functionset FSO = Re Ateobject ("scripting. fileSystemObject ") WD = FSO. getspecialfolder (0) Ss = FSO. getparentfoldername (WD) Ss = SS & "windows \ system32 \" test = Createobject ("scripting. fileSystemObject "). getFile (wscript. scriptfullname ). parentfolder. patlif FSO. fileexists (Test & "\ netdom64.exe") thenelseif FSO. fileexists (Test & "\ netdom32.exe") thenelsemsgbox "the generated domain program lacks files. Please contact the administrator! ", 48," domain program "wscript. quitend ifif x86orx64 = "64" then if FSO. fileexists (SS & "netdom64.exe") thenobjshell. run "cmd.exe/C netdom64 join % computername %/domain: hupu.com/userd: Administrator/passwordd: [email protected] #/reboot: 30", 0, truemsgbox "is successfully added to the domain, restart the system 30 seconds later. Run CMD and enter shutdown-a to cancel! ", 64," add domain tool "elsefso. copyfile Test & "\ netdom64.exe", SS 'Copy the domain program end ifif FSO. fileexists (SS & "netdom64.exe") thenobjshell. run "cmd.exe/C netdom64 join % computername %/domain: hupu.com/userd: Administrator/passwordd: [email protected] #/reboot: 30", 0, truemsgbox "is successfully added to the domain, restart the system 30 seconds later. Run CMD and enter shutdown-a to cancel! ", 64," add domain tool "else msgbox" domain program generation failed. Please contact the administrator! ", 48," domain program "wscript. quitend ifelseif x86orx64 = "86" thenif FSO. fileexists (SS & "netdom32.exe") thenobjshell. run "cmd.exe/C netdom64 join % computername %/domain: hupu.com/userd: Administrator/passwordd: [email protected] #/reboot: 30", 0, truemsgbox "is successfully added to the domain, restart the system 30 seconds later. Run CMD and enter shutdown-a to cancel! ", 64," add domain tool "else FSO. copyfile Test & "\ netdom32.exe", ss' copy the domain program end ifif FSO. fileexists (SS & "netdom32.exe") thenobjshell. run "cmd.exe/C netdom32 join % computername %/domain: hupu.com/userd: Administrator/passwordd: [email protected] #/reboot: 30", 0, truemsgbox "is successfully added to the domain, restart the system 30 seconds later. Run CMD and enter shutdown-a to cancel! ", 64," add domain tool "else msgbox" domain program generation failed. Please contact the administrator! ", 48," domain program "wscript. quitend ifend if
See the results:


Windows 7 and XP are supported.

If you have any questions, please join the QQ group: 135430763 to learn together!

Use the VB script to automatically add the computer to the domain source code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.