前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用vb脚本让电脑自动加入域源码

使用vb脚本让电脑自动加入域源码

作者头像
业余草
发布2019-01-21 15:42:28
1.3K0
发布2019-01-21 15:42:28
举报
文章被收录于专栏:业余草业余草

在企业用户中,一大部分用户都加入了域,用于公司的安全管理。加入域对于管理比较方便。但是新增的设备或者用户如何快速的加入已知的域呢?很简单,看代码:

代码语言:javascript
复制
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 "此客户端已经在指定的域中!",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全支持。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014年10月23日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
私有网络
私有网络(Virtual Private Cloud,VPC)是基于腾讯云构建的专属云上网络空间,为您在腾讯云上的资源提供网络服务,不同私有网络间完全逻辑隔离。作为您在云上的专属网络空间,您可以通过软件定义网络的方式管理您的私有网络 VPC,实现 IP 地址、子网、路由表、网络 ACL 、流日志等功能的配置管理。私有网络还支持多种方式连接 Internet,如弹性 IP 、NAT 网关等。同时,您也可以通过 VPN 连接或专线接入连通腾讯云与您本地的数据中心,灵活构建混合云。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档