在Win 7

时间:2016-03-19 07:28:47

标签: vbscript

我有以下vbs加入Win 7 PC到域。在运行时,它不会出错但不提供输出,也不会加入域。

任何人都可以看到问题并建议我如何添加错误捕获吗?

    'On Error Resume Next

strDomain = "domain.local" 
strPassword = "password" 
strUser = "user" 
strOU = "OU=OU1,OU=OU2,OU=OU3,OU=OU with spaces in name,DC=domain,DC=local"


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

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

' Join Domain
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, strDomain & "\" & strUser, strOU, _
JOIN_DOMAIN + ACCT_CREATE + DOMAIN_JOIN_IF_JOINED)

Select Case ReturnValue

Case 0 Status = "Success"

Case 2 Status = "Missing OU"

Case 5 Status = "Access denied"

Case 53 Status = "Network path not found"

Case 87 Status = "Parameter incorrect"

Case 1326 Status = "Logon failure, user or pass"

Case 1355 Status = "Domain can not be contacted"

Case 1909 Status = "User account locked out"

Case 2224 Status = "Computer Account already exists"

Case 2691 Status = "PC already on domain"

Case Else Status = "UNKNOWN ERROR " & ReturnValue

' Show Status
WScript.Echo "Join domain status: " & Status

End Select

1 个答案:

答案 0 :(得分:0)

您要在案例中设置变量Status,但通过WScript.Echo输出的行只会显示在Case Else上。要在End Select之后修改此行,以便您可以查看Status的所有实例的Case值。

Select Case ReturnValue
Case 0 
    Status = "Success"
Case 2 
    Status = "Missing OU"
Case 5 
    Status = "Access denied"
Case 53 
    Status = "Network path not found"
Case 87 
    Status = "Parameter incorrect"
Case 1326 
    Status = "Logon failure, user or pass"
Case 1355 
    Status = "Domain can not be contacted"
Case 1909 
    Status = "User account locked out"
Case 2224 
    Status = "Computer Account already exists"
Case 2691 
    Status = "PC already on domain"
Case Else 
    Status = "UNKNOWN ERROR " & ReturnValue
End Select

' Show Status
WScript.Echo "Join domain status: " & Status