Solved

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

Posted on 2011-02-10
2
2,846 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:ob1_
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
ob1_ earned 0 total points
ID: 34864935
Looks like the problem was UAC - I had not fully disabled in Local Security Policy.
0
 
LVL 6

Author Closing Comment

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question