Grace Fang
Grace Fang

Reputation:

.vbs script permission - 80070005

I'm having a permissions problem while running a .vbs script. The script is to add new user accounts from an receptionist's computer.

The script gets hung up on the line:

objUser.SetInfo

this is where it is actually setting the attributes and writing to the user account.

I know it's a permissions problem. I have tried running the script as a "top level" admin where permissions shouldn't be an issue, but I still get the error 80070005. It doesn't make a difference if I run it from a domain controller or workstation - same error.

I have created a simple 3 line script to create a user object to test my theory - and even the 3 line script fails on the objUser.SetInfo line.

What can I do to easily have this script run from a domain joined computer (administrative assistant's, or a receptionists)?

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 

Upvotes: 1

Views: 7297

Answers (1)

Ken White
Ken White

Reputation: 125688

The 8007 (which is actually 0x8007) indicates it's a COM error, and the 0005 means Access denied. This is a rights issue; you need to run your script as Administrator. Since it's unlikely that a receptionist or administrative assistant is the Administrator (at least I hope that's not the case), you probably aren't going to be able to do so.

For more information, search Google for vbs 0x80070005, which turns up multiple results.

Upvotes: 2

Related Questions