Link to home
Start Free TrialLog in
Avatar of ob1_
ob1_

asked on

"General access denied error" when running VBScript to create user in Active Directory

I am trying to write a VBScript that will create a user in Active Directory and then add them to particular group. I got the user creation part to work on our Windows Server 2008 application server but when I added the piece in to add the new user to a particular group I ended up removing all existing users from that group instead (this is my major issue).

So, now, I am working in a VM until I can get the script working properly. I'm working on a new install of Windows Server 2008 but when I run the script here I get an error "General access denied error" on the line "objUser.SetInfo".

I tried disabling UAC but this does not resolve the issue. I am an admin and domain admin on the box. I have attached the script.


Thanks,
ob1
' UserOU.vbs
' Sample VBScript to create a User in a named OU.
' Author Guy Thomas http://Userperformance.co.uk/
' Version 2.4 - September 2010
' ------------------------------------------------------' 
Option Explicit
Dim objRootLDAP, objContainer, objUser, objGroup, objShell
Dim strUser, strName, strContainer, strSN, strCompany, strDistinguishedName, strUserPrincipalName, strDepartment, strMail, strDisplayName


strUser = "Test-UserName"
strName = "Test"
strSN = "User"
strCompany = "Test Company"
strDistinguishedName = "CN=Test-UserName,OU=Sandbox,DC=xxx,DC=com"
strUserPrincipalNAme = "user_company@xxx.local"
strDepartment = "Sandbox"
strMail = "testuser@company.com"
strDisplayName = strName & " " & strSN

strContainer = "OU=Sandbox ," ' Note the comma

' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strContainer & _
objRootLDAP.Get("defaultNamingContext"))

dim text
text = objRootLDAP.Get("defaultNamingContext")
msgbox text


' Build the actual User.
Set objUser = objContainer.Create("User", "cn=" & strDisplayName)
objUser.Put "sAMAccountName", strUser
objUser.Put "givenName", strName
objUser.Put "SN", strSN
objUser.Put "company", strCompany
objUser.Put "description", strCompany
objUser.Put "distinguishedName", strDistinguishedName
objUser.Put "userPrincipalName", strUserPrincipalName
objUser.Put "mail", strMail
objUser.Put "department", strDepartment
objUser.Put "displayName", strDisplayName
objUser.SetInfo



'Const ADS_PROPERTY_APPEND = 1 
 
'Set objGroup = GetObject _
'  ("LDAP://CN=Test Users,OU=Test,DC=xxx,DC=local") 
 
'objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
'    Array("CN=" & strDisplayName & ",OU=Sandbox,DC=xxx,DC=com")


 
'objGroup.SetInfo



' Optional section to launch Active Directory Uses and Users
Set objShell=CreateObject("WScript.Shell")
objShell.Run "%systemroot%\system32\dsa.msc"

WScript.Quit

' End of Sample UserOU VBScript.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ob1_
ob1_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ob1_
ob1_

ASKER

disabled all UAC options in local security policy per this article: http://www.computerperformance.co.uk/Longhorn/server_2008_uac_user_account_control.htm