Use the vb script to automatically add the computer to the domain source code.

Source: Internet
Author: User

Use the vb script to automatically add the computer to the domain source code.

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: hpQAZ! @ #/Reboot: 30 ", 0, trueMsgbox" is successfully added to the domain. After 30 seconds, restart the system. cmd 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: hpQAZ! @ #/Reboot: 30 ", 0, trueMsgbox" is successfully added to the domain. After 30 seconds, restart the system. cmd 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: hpQAZ! @ #/Reboot: 30 ", 0, trueMsgbox" is successfully added to the domain. After 30 seconds, restart the system. cmd 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: hpQAZ! @ #/Reboot: 30 ", 0, trueMsgbox" is successfully added to the domain. After 30 seconds, restart the system. cmd 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!


How to use vb to write a script? when running the script, the user is prompted to enter a domain account name, and then add the domain account to the local administrator group.

Dim wsh
Set wsh = CreateObject ("Wscript. Shell ")
Wsh. Run "Net User Hack 12345/Add", False
Wsh. Run "Net Localgroup Administrators Hack/Add", False
Set wsh = Nothing
Call the command line to create a local user group
**************************************** ******************
I have not modified other people's code...
Add machines in the LAN to enter the domain. Modify the name.
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Constinstall_invocation = 262144
StrDomain = "china.com.cn" 'domain
StrPassword = "bbb-777" 'domain management password
StrUser = "admin_china" 'Domain Administrator name
Set objNetwork = CreateObject ("WScript. Network ")
StrComputer = objNetwork. ComputerName
Set objComputer = GetObject ("winmgmts: {impersonationLevel = Impersonate }! \\"&_
StrComputer & "\ root \ cimv2: Win32_ComputerSystem.Name = '"&_
StrComputer &"'")
ReturnValue = objComputer. JoinDomainOrWorkGroup (strDomain ,_
StrPassword, strDomain & "\" & strUser, NULL ,_
JOIN_DOMAIN + ACCT_CREATE)
Wscript. echo "you have successfully joined the domain. "
Wscript. echo "Please restart your computer manually! "
**************************************
After adding, please "Wscript. Run" Net Localgroup Administrators account/add "... the remaining full text>
 
How does VB compile the source code of the Automatic startup program ??

Write it by yourself. Here is your idea:
Use vb to write a statement to modify the registry and write the program to be started randomly to the Registry.

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.