我在运行.vbs脚本时遇到权限问题。该脚本是从接待员的计算机添加新的用户帐户。
脚本挂起就行了:
objUser.SetInfo
这是实际设置属性并写入用户帐户的地方。
我知道这是一个权限问题。我已经尝试将脚本作为“顶级”管理员运行,其中权限不应该是一个问题,但我仍然得到错误80070005
。如果我从域控制器或工作站运行它也没有什么区别 - 同样的错误。
我创建了一个简单的3行脚本来创建用户对象来测试我的理论 - 甚至3行脚本也在objUser.SetInfo
行失败。
我可以做些什么来轻松地从加入域的计算机(行政助理或接待员)运行此脚本?
strOU= InputBox("Enter the classification of the new User" &_
vbCrLf & "NOTE: You MUST enter 'Patients'")
If strOU = False Then Call NO_OU(1)
If strOU = "" Then Call NO_OU(2)
' If IsNumeric(strOU) = False Then Call NO_OU(3)
strName = InputBox("Enter the Logon ID of the New Patient (firstname.lastname)" &_
vbCrLf & "to be created.")
If strName = False Then Call NOName(1)
If strName = "" Then Call NOName(2)
' If IsNumeric((Left(strName,3))) = False Then Call NOName(3)
strFirstName = InputBox("Enter the New Patient's First Name")
If strFirstName = False Then Call NOName(1)
If strFirstName = "" Then Call NOName(2)
strLastName = InputBox("Enter the New Patients's Last Name")
If strLastName = False Then Call NOName(1)
If strLastName = "" Then Call NOName(2)
strtelephoneNumber = InputBox("Enter the New Patients's Telephone")
If strLastName = False Then Call NOName(1)
If strLastName = "" Then Call NOName(2)
strstreetAddress = InputBox("Enter the New Patients's Street Address")
If strLastName = False Then Call NOName(1)
If strLastName = "" Then Call NOName(2)
strl = InputBox("Enter the New Patients's city")
If strLastName = False Then Call NOName(1)
If strLastName = "" Then Call NOName(2)
strpostalCode = InputBox("Enter the New Patients's postal code")
If strLastName = False Then Call NOName(1)
If strLastName = "" Then Call NOName(2)
Call Password()
Call Main()
Call Quit(2)
Sub Main()
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
Set objRoot = GetObject("LDAP://rootDSE")
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objDomain = GetObject("LDAP://" &_
objRoot.Get("defaultNamingContext"))
Set objOU = GetObject("LDAP://OU=" &_
strOU & "," & strDNSDomain)
'Create the new User
On Error Resume Next
Set objUser = objOU.Create("User", "cn=" & strFirstName & " " & strLastName)
objUser.Put "sAMAccountName", strName
objUser.Put "givenName", strFirstName
objUser.Put "sn", strLastName
objUser.Put "distinguishedName", strFirstName & " " & strLastName
objUser.Put "displayName", strLastName & "," & strFirstName
objUser.Put "userPrincipalName", strName & "@dicksonmedical.mittens.local"
objuser.Put "telephoneNumber", strtelephoneNumber
objuser.Put "streetAddress", strstreetAddress
objuser.Put "l", strl
objuser.Put "postalCode", strpostalCode
objUser.SetInfo
If Err.number <> 0 Then Call Quit(1)
'Set User account environment
Set objUser = objOU.GetObject ("User", "cn=" & strFirstName & " " & strLastName)
Const Enabled = 1
Const Disabled = 0
If objUser.class = "user" Then
objUser.AllowLogon = Enabled
objUser.IsAccountLocked = False
objUser.SetPassword strInputReturn1
objUser.Put "pwdLastSet", Disabled
objUser.AccountDisabled = False
objUser.SetInfo
End if
'objUser.SetPassword StrPassword1
'objUser.SetPassword StrPassword2
'objUser.Put "pwdLastSet", Enabled
End Sub
Function Password()
strPassword = InputBox("Enter the User's Password")
If strPassword = False Then Call NOPassword(1)
If strPassword = "" Then Call NOPassword(2)
strConfPassword = InputBox("Enter the User's Password")
If strConfPassword = False Then Call NOPassword(1)
If strConfPassword = "" Then Call NOPassword(2)
If strPassword <> strConfPassword Then
Call PasswordMisMatch(1)
Else strInputReturn1 = strPassword
End If
End Function
Sub NO_OU(Error)
If Error = "1" Then MsgBox("Canceled")
If Error = "2" Then MsgBox("Invalid User Type Entered!" &_
vbCrLf & "Enter 'Patients'")
If Error = "3" Then MsgBox("Invalid User Type Entered!" &_
vbCrLf & "Enter 'Patients'")
Call Quit(1)
End sub
Sub NOName(Error)
If Error = "1" Then MsgBox("Canceled")
If Error = "2" Then MsgBox("User's Name not entered.")
If Error = "3" Then MsgBox("Invalid User Name" & vbCrLf &_
"Example: 888$jsmith")
Call Quit(1)
End sub
Sub NOPassword(Error)
If Error = "1" Then MsgBox("Canceled")
If Error = "2" Then MsgBox("User's Password not entered.")
Call Quit(1)
End Sub
Sub PasswordMisMatch(Error)
If Error = "1" Then MsgBox("Passwords Do NOT Match" &_
vbCrLf & "Try Again.")
Call Password()
End Sub
Sub Quit(Error1)
If Error1 = "1" Then MsgBox("Script Canceled!!")
If Error1 = "2" Then MsgBox("User Account Created.")
WScript.Quit
End Sub
Sub Sure(Error1)
If Error = "1" Then strYN = MsgBox("Are you sure?", 4, "Enter OU Prompt")
If strYN = 6 Then
If strYN = 7 Then Call Quit(1)
End If
End Sub
答案 0 :(得分:2)
8007
(实际上是0x8007
)表示它是COM错误,0005
表示Access denied
。这是一个供股问题;您需要以Administrator
运行脚本。由于接待员或行政助理不太可能Administrator
(至少我希望并非如此),您可能无法这样做。
有关详细信息,请在Google上搜索vbs 0x80070005,这会产生多个结果。