Vbscript =objComputer.UnJoinDomainOrWorkGroup(NULL,NULL) Return=objComputer.JoinDomainOrWorkGroup(“工作组”,NULL,NULL) 如果错误号为0,则 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(SystemName&“无法将其删除到工作组!”&vbCr&_ “错误:”&错误说明,,“标题”,0+16) 其他的 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(SystemName&“已成功删除到工作组!”,“Title”,0+64) 如果结束 下一个 对于colComputers中的每个对象计算机 ReturnValue=objComputer.JoinDomainOrWorkGroup(域名、ComputerAPass、ComputerALogin、OU、加入域+帐户创建) 如果错误号为0,则 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(“无法加入”&SystemName&“域!请手动加入。”,“Title”,0+16) 其他的 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(“域加入成功!”,“Title”,0+64) 如果结束 下一个

Vbscript =objComputer.UnJoinDomainOrWorkGroup(NULL,NULL) Return=objComputer.JoinDomainOrWorkGroup(“工作组”,NULL,NULL) 如果错误号为0,则 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(SystemName&“无法将其删除到工作组!”&vbCr&_ “错误:”&错误说明,,“标题”,0+16) 其他的 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(SystemName&“已成功删除到工作组!”,“Title”,0+64) 如果结束 下一个 对于colComputers中的每个对象计算机 ReturnValue=objComputer.JoinDomainOrWorkGroup(域名、ComputerAPass、ComputerALogin、OU、加入域+帐户创建) 如果错误号为0,则 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(“无法加入”&SystemName&“域!请手动加入。”,“Title”,0+16) 其他的 设置WshShell=CreateObject(“WScript.Shell”) message=WshShell.Popup(“域加入成功!”,“Title”,0+64) 如果结束 下一个,vbscript,dns,wmi,trust,workgroup,Vbscript,Dns,Wmi,Trust,Workgroup,谢谢你的点灯时刻,莉兹 好吧,我觉得没有早点想到这一点有点傻,但提到映射驱动器让我想到了这一点。我试图映射驱动器,但它一直想使用我的当前凭据或我的域以及备用域用户名。所以我尝试了“\LoginB”,但那只是使用了我的计算机名后跟“LoginB”。我最终不得不使用“SystemName\LoginB”,并成功地映射了驱动器。使用该方法,我可以通过将ComputerBLogin变量更改为以下事实上可行的变量来更正上述代码: Const JOIN_DOMAIN = 1 Cons

谢谢你的点灯时刻,莉兹

好吧,我觉得没有早点想到这一点有点傻,但提到映射驱动器让我想到了这一点。我试图映射驱动器,但它一直想使用我的当前凭据或我的域以及备用域用户名。所以我尝试了“\LoginB”,但那只是使用了我的计算机名后跟“LoginB”。我最终不得不使用“SystemName\LoginB”,并成功地映射了驱动器。使用该方法,我可以通过将ComputerBLogin变量更改为以下事实上可行的变量来更正上述代码:

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
Const INSTALL_INVOCATION      = 262144

Const WbemAuthenticationLevelPktPrivacy = 6

On Error Resume Next 

SystemName = "SystemName"
strNamespace = "root\cimv2"
ComputerBLogin = SystemName & "\LoginB"
ComputerBPass = "PassB"
ComputerALogin = "LoginA"
ComputerAPass = "PassA"
DomainName = "domain.com"
OU = "OU=desiredou,DC=domain,DC=com"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & SystemName & "\root\cimv2")

If Err.Number <> 0 Then

    Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objwbemLocator.ConnectServer(SystemName, strNamespace, ComputerBLogin, ComputerBPass)

    objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

    Err.Clear
End IF

Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
    Return = objComputer.UnJoinDomainOrWorkGroup(NULL, NULL)
    Return = objComputer.JoinDomainOrWorkGroup("WORKGROUP", NULL, NULL)
    If Err.Number <> 0 Then
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup (SystemName & " could not be dropped to the workgroup!" & vbCr &_
                "Error: " & Err.Description,, "Title", 0 + 16)
    Else
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup (SystemName & " was successfully dropped to the WORKGROUP!",, "Title", 0 + 64)
    End If
Next

For Each objComputer in colComputers
    ReturnValue = objComputer.JoinDomainOrWorkGroup(DomainName, ComputerAPass, ComputerALogin, OU, JOIN_DOMAIN + ACCT_CREATE)

    If Err.Number <> 0 Then
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup ("Unable to join " & SystemName & " to the domain! Please join manually.",, "Title", 0 + 16)
    Else
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup ("Domain joining was successful!",, "Title", 0 + 64)
    End If
Next
Const JOIN\u DOMAIN=1
Const ACCT_CREATE=2
常量帐户删除=4
常量WIN9X_升级=16
常量域\u JOIN\u如果\u JOIN=32
Const JOIN_UNSECURE=64
Const MACHINE\u PASSWORD\u PASSED=128
常量延迟\u SPN\u集=256
Const INSTALL_调用=262144
常量WbemAuthenticationLevelPktPrivacy=6
出错时继续下一步
SystemName=“SystemName”
strNamespace=“root\cimv2”
ComputerBLogin=SystemName&“\LoginB”
ComputerBPass=“PassB”
ComputerALogin=“LoginA”
ComputerAPass=“PassA”
DomainName=“domain.com”
OU=“OU=desiredou,DC=domain,DC=com”
设置objWMIService=GetObject(“winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\”&SystemName&“\root\cimv2”)
如果错误号为0,则
设置objWbemLocator=CreateObject(“WbemScripting.SWbemLocator”)
设置objWMIService=objwbemLocator.ConnectServer(SystemName、strNamespace、ComputerBLogin、ComputerBPass)
objWMIService.Security\uux.authenticationLevel=WbemAuthenticationLevelPktPrivacy
呃,明白了
如果结束
Set colComputers=objWMIService.ExecQuery(“从Win32\u ComputerSystem中选择*)
对于colComputers中的每个对象计算机
Return=objComputer.UnJoinDomainOrWorkGroup(NULL,NULL)
Return=objComputer.JoinDomainOrWorkGroup(“工作组”,NULL,NULL)
如果错误号为0,则
设置WshShell=CreateObject(“WScript.Shell”)
message=WshShell.Popup(SystemName&“无法将其删除到工作组!”&vbCr&_
“错误:”&错误说明,,“标题”,0+16)
其他的
设置WshShell=CreateObject(“WScript.Shell”)
message=WshShell.Popup(SystemName&“已成功删除到工作组!”,“Title”,0+64)
如果结束
下一个
对于colComputers中的每个对象计算机
ReturnValue=objComputer.JoinDomainOrWorkGroup(域名、ComputerAPass、ComputerALogin、OU、加入域+帐户创建)
如果错误号为0,则
设置WshShell=CreateObject(“WScript.Shell”)
message=WshShell.Popup(“无法加入”&SystemName&“域!请手动加入。”,“Title”,0+16)
其他的
设置WshShell=CreateObject(“WScript.Shell”)
message=WshShell.Popup(“域加入成功!”,“Title”,0+64)
如果结束
下一个

谢谢你的点灯时刻,莉兹

有人吗?即使答案是“除了手动删除和重新加入之外,您无法以任何其他方式解决此问题”,也没关系。希望有人能对此有所了解,有人吗?即使答案是“除了手动删除和重新加入之外,您无法以任何其他方式解决此问题”,也没关系。希望有人能对此有所了解。谢谢你的回复Lizz。我尝试了您的建议,删除对象,重新启动工作站,然后再次尝试本地管理员凭据-不幸的是,我得到了相同的结果。我仍然认为这是可行的,因为我能够使用RDP和本地管理凭据并成功登录。因此,这是一种通过网络传递信任的远程通信形式,如果这种方式有效的话,从逻辑上讲,人们会认为有一种编程方式可以做到这一点,我只是还没有找到方法。我尝试过psexec,但与netdom类似,它会在信任关系信息中出错。虽然不在域中,但操作系统防火墙可能会“弹出”以阻止除RDP(3389)之外的所有端口。在这种状态下,您可以连接到它的RPC端口吗?这些是TCP端口135、139和445。Telnet是连接到TCP端口的简单方法。:)很好的建议!因此,您提到的所有端口(3389、135、139和445)都正确连接。尽管标准telnet(23)失败了。因此,我们知道有些端口被阻塞,有些端口现在没有。那么,我该如何指示我的脚本只通过未阻塞的端口进行通信呢?或者这是可能的吗?针对RDP可以执行的大多数脚本都是登录。您的脚本已经通过RPC进行通信,RPC是开放的,因此您可以使用其本地管理员将驱动器映射到损坏主机的C$?在这种情况下,我所知道的唯一可以确定的连接是一个域服务帐户,该帐户作为损坏主机上的有效服务运行,并且该服务必须能够“被告知”执行任何操作。在这种情况下,本地管理员信誉有一个不确定的历史记录。我唯一能想到的就是使用
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & SystemName & "\root\cimv2")
Set objWMIService = objwbemLocator.ConnectServer(SystemName, strNamespace, ComputerBLogin, ComputerBPass)
strComputer = "atl-pro-040"

set objComputer = GetObject("LDAP://CN=" & strComputer & _
    ",CN=Computers,DC=fabrikam,DC=com")
objComputer.DeleteObject (0)
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
Const INSTALL_INVOCATION      = 262144

Const WbemAuthenticationLevelPktPrivacy = 6

On Error Resume Next 

SystemName = "SystemName"
strNamespace = "root\cimv2"
ComputerBLogin = SystemName & "\LoginB"
ComputerBPass = "PassB"
ComputerALogin = "LoginA"
ComputerAPass = "PassA"
DomainName = "domain.com"
OU = "OU=desiredou,DC=domain,DC=com"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & SystemName & "\root\cimv2")

If Err.Number <> 0 Then

    Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objwbemLocator.ConnectServer(SystemName, strNamespace, ComputerBLogin, ComputerBPass)

    objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

    Err.Clear
End IF

Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
    Return = objComputer.UnJoinDomainOrWorkGroup(NULL, NULL)
    Return = objComputer.JoinDomainOrWorkGroup("WORKGROUP", NULL, NULL)
    If Err.Number <> 0 Then
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup (SystemName & " could not be dropped to the workgroup!" & vbCr &_
                "Error: " & Err.Description,, "Title", 0 + 16)
    Else
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup (SystemName & " was successfully dropped to the WORKGROUP!",, "Title", 0 + 64)
    End If
Next

For Each objComputer in colComputers
    ReturnValue = objComputer.JoinDomainOrWorkGroup(DomainName, ComputerAPass, ComputerALogin, OU, JOIN_DOMAIN + ACCT_CREATE)

    If Err.Number <> 0 Then
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup ("Unable to join " & SystemName & " to the domain! Please join manually.",, "Title", 0 + 16)
    Else
        Set WshShell = CreateObject("WScript.Shell")
        message = WshShell.Popup ("Domain joining was successful!",, "Title", 0 + 64)
    End If
Next