那里有数百篇文章教导这一点,但我的情况是“独特的”。所以我在下面的行中被拒绝访问:
Set objDomainUser = GetObject("WinNT://" & domainControllerIP & "/" & domainAccount & ",user")
所以我意识到我必须传递用户的凭据。大多数人只通过域名,这很好。它将连接到可以通过查看环境变量 %LOGONSERVER% 知道的域控制器。我需要指定域控制器名称(或 IP),否则它对我们不起作用。
所以我只是想让这个sintax正确。这是我的代码:
Sub AddAccountToLocalGroup(domainName, domainControllerIP, localGroup, domainAccount)
Dim localComputer : localComputer = GetMachineName()
Dim objLocalGroup
Dim objDomainUser
const ADS_SECURE_AUTHENTICATION = &h0001
const ADS_SERVER_BIND = &h0200
Set objLocalGroup = GetObject("WinNT://" & localComputer & "/" & localGroup & ",group")
'Set objDomainUser = GetObject("WinNT://" & domainControllerIP & "/" & domainAccount & ",user") 'ACCESS DENIED
'Error happens in Set objDomainUser
' Set objDomainUser = GetObject("WinNT:").OpenDSObject("WinNT://" & domainName & "/" & domainControllerIP & "/" & "Bob", "Bob", "Password", ADS_SECURE_AUTHENTICATION or ADS_SERVER_BIND)
' Set objDomainUser = GetObject("WinNT:").OpenDSObject("WinNT://" & domainName & "/" & domainControllerIP & "/" & "Bob", "Bob", "Password", ADS_SECURE_AUTHENTICATION or ADS_SERVER_BIND)
' Set objDomainUser = GetObject("WinNT:").OpenDSObject("WinNT://" & domainName & "/" & domainControllerIP & "/" & ",user", "Bob", "Password", ADS_SECURE_AUTHENTICATION or ADS_SERVER_BIND)
' Set objDomainUser = GetObject("WinNT:").OpenDSObject("WinNT://" & domainName & "/" & "Bob" & ",user", "Bob", "Password", ADS_SECURE_AUTHENTICATION or ADS_SERVER_BIND)
'Add domain user to local group
objLocalGroup.Add(objDomainUser.ADsPath)
If Err.Number <> 0 Then
WScript.Echo Err.Number
Else
WScript.Echo domainAccount & " has been added to local group."
End If
End Sub
谢谢!