[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

VB script that creates user accounts problem

Asked by creville in Visual Basic Programming

Tags: user, vb, script, accounts, creates

I have a script that I found on the internet that creates user accounts and shares etc... I am having a couple problems I am hoping to get help with. I have exausted my ability. Any help with any of the following would be great. They are listed in priority order. 1 being most important.
Thanks a million. or at least 500.

1. When permissions are set on the share, it is giving share permissions not NTFS permissions. My goal is to have everyone full on share permission and have local admin, domain admin, and the user on NTFS. I have read comments on using xacls but not sure how to inject into current script.

2. Set the flags for do not allow user to change password.

3. Set the flag for password never expires.

4. When the user account is created there is no , between last name and first name. In users and computers it is created as Doe John, i would like Doe, John.


'Option Explicit
Dim WshShell, fso
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objIADs = GetObject("LDAP://RootDSE")
Set ADSystemInfo = WScript.CreateObject("ADSystemInfo")
Set shell = wscript.createobject("WScript.Shell")
Set environment = shell.environment("PROCESS")


'logonserver = environment.Item("LOGONSERVER")
logonserver = "MOBSDC1"
DomainDNSName = ADSystemInfo.DomainDNSName
DomainDN = objIADs.Get("defaultNamingContext")
OUName = "Users"
'MsgBox logonserver
Set dom = GetObject("LDAP://" & logonserver & "/" & DomainDN)
InputPrompt1 = "Domain = "&DomainDNSName&vbCrLf&"Container = "&OUName&vbCrLf&vbCrLf&"Enter First Initial and Last Name:"
InputPrompt2 = "Domain = "&DomainDNSName&vbCrLf&"Container = "&OUName&vbCrLf&vbCrLf&"Enter Users First Name:"
InputPrompt3 = "Domain = "&DomainDNSName&vbCrLf&"Container = "&OUName&vbCrLf&vbCrLf&"Enter Users Surname:"
InputPrompt4 = "Domain = "&DomainDNSName&vbCrLf&"Container = "&OUName&vbCrLf&vbCrLf&"Enter Users Job Title:"
InputPrompt5 = "Domain = "&DomainDNSName&vbCrLf&"Container = "&OUName&vbCrLf&vbCrLf&"Enter Users Password:"
UserName = InputBox(InputPrompt1, "UserInitials")
FirstName = InputBox(InputPrompt2, "FirstName")
Surname = InputBox(InputPrompt3, "Surname")
Department = InputBox(InputPrompt4, "Job Title")
DefaultPassword = InputBox(InputPrompt5)
Set usr = dom.Create("user", "CN=" & Surname & " " & FirstName & ",CN=" & OUName)
Set ProfileServer = fso.GetFolder("\\mobsdc1\profiles$")
Set HomeServer = fso.GetFolder("\\mobsfil1\users$")

'Create User
usr.put "samAccountName", LCase(UserName)
usr.put "userPrincipalName", UserName & "@" & DomainDNSName
usr.put "givenName", FirstName
usr.put "sn", Surname
usr.put "displayName", Surname & ", " & FirstName
'usr.put "initials", LCase(Mid(UserName,2,1))
usr.put "description", Department
usr.put "homeDirectory", "\\mobsfil1\" & LCase(UserName) & "$"
usr.put "homeDrive", "H:"
usr.put "profilePath", "\\mobsdc1\profiles$\" & LCase(UserName)
'Usr.put "logonScript", "SLogic"

usr.setinfo
usr.setpassword DefaultPassword
usr.accountdisabled = False
usr.setinfo

'Create Users Mailbox
Dim oIADSUser
Dim MStore
Set oIADSUser = GetObject("LDAP://" & logonserver & "/CN=" & Surname & " " & FirstName & ",CN=Users," & DomainDN)


MStore = "Mailbox Store (MOBSXCH1)"

 oIADSUser.CreateMailbox ("LDAP://" & logonserver & "/CN=Mailbox Store (MOBSXCH1),CN=First Storage Group,CN=InformationStore,CN=MOBSXCH1,CN=Servers,CN=MOBILE,CN=Administrative Groups,CN=Mobile Register,CN=Microsoft Exchange,CN=Services,CN=Configuration," & DomainDN)
oIADSUser.SetInfo

'Add member to groups
Const ADS_PROPERTY_APPEND = 3
 
Set objGroup = GetObject("LDAP://CN=Everyone,OU=Exchange Distribution Groups," & DomainDN)
objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array("CN=" & Surname & " " & FirstName & ",cn=Users," & DomainDN)
objGroup.SetInfo

'Wscript.quit

'Create users home directory
If fso.FolderExists(HomeServer & "\" & UserName) = False Then
 fso.CreateFolder(HomeServer & "\" & LCase(UserName))
 'fso.CreateFolder(ProfileServer & "" & UserName & "interface")
End If

'Share user home directory
AdminServer = "MOBSFIL1"
ShareName = LCase(Username) & "$"
FolderName = "D:\users\" & UserName
'Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!\\" & AdminServer & "ROOT\CIMV2")
Set Services = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & AdminServer & "\root\cimv2")
Set SecDescClass = Services.Get("Win32_SecurityDescriptor")
Set SecDesc = SecDescClass.SpawnInstance_()
Set Share = Services.Get("Win32_Share")
Set InParam = Share.Methods_("Create").InParameters.SpawnInstance_()
InParam.Properties_.Item("Access") = SecDesc
InParam.Properties_.Item("Description") = "Home Directory"
InParam.Properties_.Item("Name") = ShareName
InParam.Properties_.Item("Path") = FolderName
InParam.Properties_.Item("Type") = 0
Share.ExecMethod_"Create", InParam


ReplaceACL "\\mobsfil1\" & LCase(UserName) & "$","add(" & UserName & ":F)+add(domain admins:F)"


Set WshShell = Nothing
Set fso = Nothing
Set WshNetwork = Nothing
Set usr = Nothing
Set NewShare = Nothing
Set Services = Nothing
Set SecDescClass = Nothing
Set SecDesc = Nothing
Set Share = Nothing
Set InParam = Nothing
Set sec = Nothing
Set sd = Nothing
Set dacl = Nothing
Set ace = Nothing
Set oIADSUser = Nothing
Set objGroup = Nothing

MsgBox "The creation of user: " & FirstName & " " & Surname & VbCrLf &_
  "has completed without error"


'Functions

'Set permissions on users home directory
Function ReplaceACL(foldernm, permspart)
 foldernm = HomeServer & "\" & UserName
 If fso.FolderExists(foldernm)= False Then
  MsgBox "Sorry this folder is not present on the server"
 Else
  ChangeACLS foldernm, permspart, "REPLACE", "FOLDER"
 End If
End Function

'Edit ACLS of specified folder
Function ChangeAcls(FILE,PERMS,REDIT,FFOLDER)

 Const ADS_ACETYPE_ACCESS_ALLOWED = 0
 Const ADS_ACETYPE_ACCESS_DENIED = 1
 Const ADS_ACEFLAG_INHERIT_ACE = 2
 Const ADS_ACEFLAG_SUB_NEW = 9
 Const ADS_PATH_FILESHARE = 2
 Const ADS_SD_FORMAT_IID = 1
     
 Set sec = Wscript.CreateObject("ADsSecurityUtility")
 Set sd = sec.GetSecurityDescriptor("\\mobsfil1\" & LCase(UserName) & "$", ADS_PATH_FILESHARE, ADS_SD_FORMAT_IID)
 Set dacl = sd.DiscretionaryAcl

 If UCase(REDIT)="REPLACE" Then
  For Each existingAce In dacl
  dacl.removeace existingace
  Next
 End If
     
 'break up Perms into individual actions
 cmdArray=split(perms,"+")
   
 For x=0 to ubound(cmdarray)
 tmpVar1=cmdarray(x)
 If UCase(left(tmpVar1,3))="DEL" Then
  ACLAction="DEL"
 Else
  ACLAction="ADD"
 End If

 tmpcmdVar=left(tmpVar1,len(tmpVar1)-1)
 tmpcmdVar=right(tmpcmdVar,len(tmpcmdVar)-4)
 cmdparts=split(tmpcmdVar,":")
 nameVar=cmdparts(0)
 rightVar=cmdparts(1)

 If ACLAction="ADD" Then
  If UCase(FFOLDER)="FOLDER" Then
   addace dacl, namevar, rightvar, ADS_ACETYPE_ACCESS_ALLOWED, ADS_ACEFLAG_SUB_NEW
   addace dacl, namevar, rightvar, ADS_ACETYPE_ACCESS_ALLOWED, ADS_ACEFLAG_INHERIT_ACE
  Else
   addace dacl, namevar, rightvar, ADS_ACETYPE_ACCESS_ALLOWED,0
  End If
 End If
 Next

 For Each ace in dacl
  If instr(ucase(ace.trustee),"NT AUTHORITY") then
   newtrustee=right(ace.trustee, len(ace.trustee)-instr(ace.trustee, ""))
   ace.trustee=newtrustee
  End If
 Next

 sd.DiscretionaryAcl = dacl
 sec.SetSecurityDescriptor "\\mobsfil1\" & LCase(UserName) & "$", ADS_PATH_FILESHARE, SD, ADS_SD_FORMAT_IID

End Function

Function addace(dacl,trustee, maskvar, acetype, aceflags)
 ' add ace to the specified dacl
 Const RIGHT_READ = &H80000000
 Const RIGHT_EXECUTE = &H20000000
 Const RIGHT_WRITE = &H40000000
 Const RIGHT_DELETE = &H10000
 Const RIGHT_FULL = &H10000000
 Const RIGHT_CHANGE_PERMS = &H40000
 Const RIGHT_TAKE_OWNERSHIP = &H80000
     
 Set ace = CreateObject("AccessControlEntry")
 ace.Trustee = trustee
 
 Select Case UCase(MaskVar)
 Case "F"
 ace.AccessMask = RIGHT_FULL
 Case "C"
 ace.AccessMask = RIGHT_READ or RIGHT_WRITE or RIGHT_EXECUTE or RIGHT_DELETE
 Case "R"
 ace.AccessMask = RIGHT_READ or RIGHT_EXECUTE
 End Select

 ace.AceType = acetype
 ace.AceFlags = aceflags
 dacl.AddAce ace
End Function


[+][-]09/21/06 02:29 AM, ID: 17567607Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/21/06 02:47 AM, ID: 17567654Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/21/06 03:55 AM, ID: 17567902Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/21/06 07:45 AM, ID: 17569643Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/21/06 08:09 AM, ID: 17569874Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Visual Basic Programming
Tags: user, vb, script, accounts, creates
Sign Up Now!
Solution Provided By: Chris-Dent
Participating Experts: 1
Solution Grade: A
 
[+][-]09/21/06 10:04 AM, ID: 17571087Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/21/06 11:20 AM, ID: 17571754Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81