码迷,mamicode.com
首页 > 其他好文 > 详细

使用vb脚本让电脑自己主动增加域源代码

时间:2017-07-16 11:29:38      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:安全管理   str   x64   quit   min   技术分享   部分   copy   code   

在企业用户中,一大部分用户都增加了域。用于公司的安全管理。增加域对于管理比較方便。可是新增的设备或者用户怎样高速的增加已知的域呢?非常easy,看代码:

set objShell=wscript.createObject("wscript.shell")
strComputer = "."
Dim WshNetwork
Dim strComputer
Set WshNetwork = WScript.CreateObject("WScript.Network")
strDomain = WshNetwork.UserDomain
if strDomain = "HUPU" then
	Msgbox "此client已经在指定的域中!",64,"增加域工具"
	Wscript.Quit
end if

Msgbox "确定增加域。整个过程大概要1分钟左右",64,"增加域工具"
objShell.Run "cmd.exe /c netsh interface ip set dns ""本地连接"" static 10.10.2.116 primary",0,true
objShell.Run "cmd.exe /c netsh interface ip add dns ""本地连接"" 114.114.114.114",0,true

objShell.Run "cmd.exe /c sc config LmHosts start= AUTO",0,true
objShell.Run "cmd.exe /c net start lmhosts",0,true


Function X86orX64()
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.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 Function

Set FSO = CreateObject("Scripting.FileSystemObject") 
WD = FSO.GetSpecialFolder(0)
SS = FSO.GetParentFolderName(WD)
SS = SS & "windows\system32\"
test = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path

if FSO.FileExists(test & "\netdom64.exe") then

elseif FSO.FileExists(test & "\netdom32.exe") then

else
	Msgbox "生成域程序缺少文件。请联系管理员!",48,"域程序" 
	Wscript.Quit
end if

if X86orX64 = "64" then 
	if FSO.FileExists(SS & "netdom64.exe") then
		objShell.Run "cmd.exe /c netdom64 join %COMPUTERNAME% /domain:hupu.com /UserD:administrator /PasswordD:hpQAZ!@# /reboot:30",0,true
		Msgbox "增加域成功,30秒后重新启动系统,cmd输入shutdown -a取消!",64,"增加域工具"
	else
		FSO.copyfile test & "\netdom64.exe", SS '拷贝域程序
	end if
	
	if FSO.FileExists(SS & "netdom64.exe") then
		objShell.Run "cmd.exe /c netdom64 join %COMPUTERNAME% /domain:hupu.com /UserD:administrator /PasswordD:hpQAZ!@# /reboot:30",0,true
		Msgbox "增加域成功,30秒后重新启动系统,cmd输入shutdown -a取消!",64,"增加域工具"
	else 
        	Msgbox "域程序生成失败。请联系管理员!",48,"域程序" 
		Wscript.Quit
	end if

elseif X86orX64 = "86" then
	if FSO.FileExists(SS & "netdom32.exe") then
		objShell.Run "cmd.exe /c netdom64 join %COMPUTERNAME% /domain:hupu.com /UserD:administrator /PasswordD:hpQAZ!@# /reboot:30",0,true
		Msgbox "增加域成功,30秒后重新启动系统,cmd输入shutdown -a取消!",64,"增加域工具"
	else 
		FSO.copyfile test & "\netdom32.exe", SS '拷贝域程序
	end if
	if FSO.FileExists(SS & "netdom32.exe") then
		objShell.Run "cmd.exe /c netdom32 join %COMPUTERNAME% /domain:hupu.com /UserD:administrator /PasswordD:hpQAZ!@# /reboot:30",0,true
		Msgbox "增加域成功,30秒后重新启动系统,cmd输入shutdown -a取消!",64,"增加域工具"
	else 
        	Msgbox "域程序生成失败,请联系管理员!",48,"域程序" 
		Wscript.Quit
	end if
	
end if
看看效果:

技术分享
win7,xp全支持。

如有疑问,请加qq群:135430763 共同学习!


使用vb脚本让电脑自己主动增加域源代码

标签:安全管理   str   x64   quit   min   技术分享   部分   copy   code   

原文地址:http://www.cnblogs.com/jzdwajue/p/7189735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!