1
那裏有數百篇文章講授,但我的案例是「獨特的」。所以我得到訪問被拒絕的行:如何將域帳戶用戶添加到本地組?
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
謝謝!
這幫了我很多。謝謝你,先生! – Max 2013-02-21 17:28:40
現在唯一的問題是如何在循環中獲取用戶帳戶對象? Set objDomainUser = GetObject(「WinNT://」&... – Max 2013-02-21 19:39:52
以前我試過,它給了我「Microsoft VBScript運行時錯誤:權限被拒絕:'GetObject'」 請記住,VBScript(cmd.exe )在SYSTEM帳戶下運行,但如果我傳遞憑據以訪問AD對象,那應該沒關係。 注意:如果我在使用MY帳戶登錄時運行腳本,那麼腳本可以工作!但我需要在SYSTEM帳戶下完成這項工作並將證書傳遞給WinNT/LDAP等等...... – Max 2013-02-22 15:33:47