Re: User Creation via HTA

Tech-Archive recommends: Fix windows errors by optimizing your registry



I have been building something very similar in ASP on 2003, I have an
addition to add if you want, TS. See code below.

'Terminal Services
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Build object call
strUserObject = "LDAP://cn="; & strName & "," & strContainer & "," &
strHomeDomain

Set objUser = GetObject (strUserObject)

objUser.ConnectClientDrivesAtLogon = Enabled
objUser.ConnectClientPrintersAtLogon = Enabled
objUser.DefaultToMainPrinter = Enabled
objUser.TerminalServicesInitialProgram = strTSInitial
objUser.TerminalServicesWorkDirectory = strTSWrkDir

objUser.TerminalServicesProfilePath = strTSHome & strName
objUser.TerminalServicesHomeDirectory = strHomeDirectory
objUser.TerminalServicesHomeDrive = strHomeDrive
objUser.AllowLogon = Enabled

objUser.MaxDisconnectionTime = 2880
objUser.MaxConnectionTime = 1440
objUser.MaxIdleTime = 180
objUser.BrokenConnectionAction = Enabled
objUser.ReconnectionAction = Enabled

objUser.SetInfo

--


Paul Bergson MCT, MCSE, MCSA, CNE, CNA, CCA

This posting is provided "AS IS" with no warranties, and confers no rights.


"Cary Shultz [A.D. MVP]" <cwshultz@xxxxxxxx> wrote in message
news:uqS1bakyFHA.2132@xxxxxxxxxxxxxxxxxxxxxxx
> Good morning Everyone!
>
> With the help/assistance of a couple of very nice people I have created an
> HTA that creates a mail-enabled user account object, populates most of the
> AD fields, creates several network folders with the correct permissions
> and joins that user account object to several security groups. Please
> find below the 'code'. Simply save it in Notepad as 'whatever.hta' and
> use Internet Explorer to open it up and away you go. Please note that you
> will have to modify a few things for it to work in your environment. Also
> please note that it has a very basic interface that you can customize to
> your tastes.
>
> You will have to go to the Internet and download SetACL.exe ( or use
> something else, like cacls or xcacls ) and put that .exe file and this
> .hta file in the same folder. Otherwise the permissions on the folder(s)
> will not work....
>
> Code starts here---------------------------------------------
>
> <html>
> <HTA:APPLICATION
> APPLICATIONNAME="User Account Object Creation"
> SCROLL="no"
> SINGLEINSTANCE="yes"
> WINDOWSTATE="normal"
>>
>
>
> <head>
>
> <title>User Account Object Creation Form</title>
>
> <style type="text/css">
>
> <!--
>
> .style3 {font-size: 13px}
> body,td,th {
> font-family: Arial, Helvetica, sans-serif;
> }
>
> .style2 { font-family: Arial, Helvetica, sans-serif;
> font-size: 13.5pt;
> color: #008080;
> font-weight: bold;
> }
>
> .style5 {font-size: small; color: #FF0000}
>
> .style6 {color: #FF0000}
>
> -->
>
> </style>
>
> <script type="text/vbscript">
>
> Dim defaultNC
> defaultNC = GetObject("LDAP://RootDSE";).Get("DefaultNamingContext")
> BaseOU = "OU=Offices," & defaultNC
>
> Sub CreateAccount
>
>
>
> ' ##### -----Create the sAMAccountName for the user account object-----
> #####
>
> strUser = TextUser.Value
> If strUser = "" Then 'Line 50
> MsgBox "You're missing required fields.",64, "Alert"
> Exit Sub
> End If
>
> ' ##### -----end of section----- #####
>
>
>
> ' @@@@@ -----Set the first name for the user account object:Required-----
> @@@@@
>
> strFirst = TextFirst.Value
> If strFirst = "" Then
> MsgBox "You're missing required fields",64, "Alert"
> Exit Sub
> End If
>
> ' @@@@@ -----end of section----- @@@@@
>
>
>
> ' ##### -----Set the middle initial for the user account object----- #####
>
> strInitial = TextInitial.Value
>
> ' ##### -----end of section----- #####
>
>
>
> ' @@@@@ -----Set the last name for the user account object:Required-----
> @@@@@
>
> strLast = TextLast.Value
> If strLast = "" Then
> MsgBox "You're missing required fields",64, "Alert"
> Exit Sub
> End If
>
> ' @@@@@ -----end of section----- @@@@@
>
>
>
> ' ##### -----Set the variables for the user account objects----- #####
>
> strDisplay = strLast & ", " & strFirst
> strCN = strLast & "\, " & strFirst
> strPubFldrName = strFirst & " " & strLast
> strHomeFldrName = strUser
> strDomain = "yourdomain.com"
> strMail = strUser & "@" & strDomain
>
> ' ##### -----end of section----- ##### Line 100
>
>
>
> ' @@@@@ -----Check to make sure that the user account object does not
> already exist----- @@@@@
>
> Set objConnection = CreateObject("ADODB.Connection")
> objConnection.Open "Provider=ADsDSOObject;"
>
> Set objCommand = CreateObject("ADODB.Command")
> objCommand.ActiveConnection = objConnection
>
> objCommand.CommandText = _
> "<GC://" & defaultNC & ">;(&(objectCategory=Person)(objectClass=user)" & _
> "(samAccountName=" & strUser & "));samAccountName;subtree"
>
> Set objRecordSet = objCommand.Execute
>
> If objRecordSet.RecordCount = 0 Then
>
> Else
> MsgBox "The User Account already exists.",48,"Alert"
> Exit Sub
> End If
>
> objConnection.Close
>
> ' @@@@@ -----end of section----- @@@@@
>
>
>
> Const ADS_UF_ACCOUNTDISABLE = 2
> Const ADS_PROPERTY_UPDATE = 2
>
>
>
> ' ##### -----Determine the DNS domain from the RootDSE object----- #####
>
> Set objRootDSE = GetObject("LDAP://RootDSE";)
> strDNSDomain = objRootDSE.Get("DefaultNamingContext")
>
> ' ##### -----end of section----- #####
>
>
>
> If Site.Value = "LocationAlert" Then
> MsgBox "You must select the Users Location.",64, "Alert"
> Exit Sub
> End If
>
> Select Case Site.Value ' Line 150
>
> Case "Roanoke"
> strOffice = "Roanoke"
> strLDAPdn = "OU=Roanoke," & BaseOU
> strUserSrvr = "ROA-DC01"
> strHomeFldr = "home$"
> strPublicFldr = "public"
> strTelephone = "540.555.1234"
> strAddress = "1 Main Street"
> strCity = "Roanoke"
> strState = "VA"
> strZip = "24012"
>
> Case "Richmond"
> strOffice = "Richmond"
> strLDAPdn = "OU=Richmond," & BaseOU
> strUserSrvr = "ROA-DC01"
> strHomeFldr = "home$"
> strPublicFldr = "public"
> strTelephone = "804.555.1111"
> strAddress = "1 Main Street"
> strCity = "Richmond"
> strState = "VA"
> strZip = "22178"
>
> Case "Blacksburg"
> strOffice = "Blacksburg"
> strLDAPdn = "OU=Blacksburg," & BaseOU
> strUserSrvr = "ROA-DC01"
> strHomeFldr = "home$"
> strPublicFldr = "public"
> strTelephone = "540.555.1235"
> strAddress = "1 Main Street"
> strCity = "Blacksburg"
> strState = "VA"
> strZip = "24179"
>
> Case "Raleigh"
> strOffice = "Raleigh"
> strLDAPdn = "OU=Raleigh," & BaseOU
> strUserSrvr = "ROA-DC01"
> strTelephone = "704.555.1235"
> strHomeFldr = "home$"
> strPublicFldr = "public"
> strAddress = "1 Main Street"
> strCity = "Raleigh"
> strState = "NC"
> strZip = "27245"
>
> End Select ' Line 200
>
> ' Create the user account object with basic information
> Set objOU = GetObject("LDAP://"; & strLDAPdn)
> Set objUser = objOU.Create("User", "cn=" & strCN)
> objUser.Put "sAMAccountName", LCase(strUser)
> objUser.Put "userPrincipalName", LCase(strUser) & "@" & strDomain
>
> ' Create the first name for user account object
> objUser.Put "givenName", strFirst
>
> ' Create the middle initial for user account object
> If strInitial <> "" Then
> objUser.Put "initials", strInitial
> End If
>
> ' Create the last name for user account object
> objUser.Put "sn", strLast
> objUser.SetInfo
>
> ' Create General Page information for the user account object
> objUser.Put "physicalDeliveryOfficeName", strOffice
> objUser.Put "telephoneNumber",strTelephone
> objUser.Put "wWWHomePage","http://www."; & strDomain
> objUser.Put "displayName", strDisplay
>
> ' Create Address information for the user account object
> objUser.Put "streetAddress", strAddress
> objUser.Put "l", strCity
> objUser.Put "st",strState
> objUser.Put "postalCode",strZip
> objUser.Put "co","United States"
> objUser.Put "c","US"
> objUser.Put "countryCode","840"
> objUser.Put "mail", strMail
>
> ' Create Organization information for the user account object
> objUser.Put "Company","YourDomain, Inc."
>
> ' Create the password for the user account object
> objUser.SetPassword "p@ssw0rd"
> objUser.Put "pwdLastSet", 0
>
> intUAC = objUser.Get("userAccountControl")
> If intUAC And ADS_UF_ACCOUNTDISABLE Then
> objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE
> End If
> objUser.SetInfo
>
> Const ADS_PROPERTY_APPEND = 3
> ' Line 250
> ' Make the user account object a member of the following group
> Set objGroup = GetObject _
> ("LDAP://cn=XYZ,"; & BaseOU)
> objGroup.PutEx ADS_PROPERTY_APPEND, _
> "member", Array("cn=" & strCN & "," & strLDAPdn)
> objGroup.SetInfo
>
> ' Make the user account object a member of the following group
> Set objGroup = GetObject _
> ("LDAP://cn=123,"; & strLDAPdn)
> objGroup.PutEx ADS_PROPERTY_APPEND, _
> "member", Array("cn=" & strCN & "," & strLDAPdn)
> objGroup.SetInfo
>
>
> If MailBoxStore.Value = "LocationAlert" Then
> MsgBox "You must select the Users Mail Box.",64, "Alert"
> Exit Sub
> End If
>
>
> Select Case MailBoxStore.Value
>
> Case "AsstMBS1"
> strExchSRVR = "ROA-DC01"
> strMBStore = "AMBS1 (ROA-DC01)"
> strStoreGRP = "First Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> Case "MngrMBS1"
> strExchSRVR = "ROA-DC01"
> strMBStore = "MMBS1 (ROA-DC01)"
> strStoreGRP = "First Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> Case "AsstMBS2"
> strExchSRVR = "ROA-DC01"
> strMBStore = "AMBS2 (ROA-DC01)"
> strStoreGRP = "Second Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> Case "MngrMBS2"
> strExchSRVR = "ROA-DC01"
> strMBStore = "MMBS2 (ROA-DC01)"
> strStoreGRP = "Second Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
> ' Line 301
> Case "AsstMBS3"
> strExchSRVR = "ROA-DC01"
> strMBStore = "AMBS3 (ROA-DC01)"
> strStoreGRP = "Third Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> Case "MngrMBS3"
> strExchSRVR = "ROA-DC01"
> strMBStore = "MMBS3 (ROA-DC01)"
> strStoreGRP = "Third Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> Case "AsstMBS4"
> strExchSRVR = "ROA-DC01"
> strMBStore = "AMBS4 (ROA-DC01)"
> strStoreGRP = "Forth Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> Case "MngrMBS4"
> strExchSRVR = "ROA-DC01"
> strMBStore = "AMBS4 (ROA-DC01)"
> strStoreGRP = "Forth Storage Group"
> strAdminGRP = "First Administrative Group"
> strExchORG = "yourdomain"
>
> End Select
>
> ' Creates the users mailbox
> Set objIADSUser = GetObject("LDAP://CN="; & strCN & "," & strLDAPdn)
> objIADSUser.CreateMailbox("LDAP://CN="; & strMBStore & ",CN=" & strStoreGRP
> & ",CN=InformationStore,CN=" & strExchSRVR & ",CN=Servers,CN=" &
> strAdminGRP & ",CN=Administrative Groups,CN=" & strExchORG &
> ",CN=Microsoft
> Exchange,CN=Services,CN=Configuration,DC=yourdomain,DC=com")
> objIADSUser.SetInfo
>
> ' The path is as follows: CN=name of Mailbox Store,CN=name of Storage
> Group,CN=InformationStore,CN=name of Exchange Server,
> ' CN=Servers,CN=name of Administrative Group,CN=Administrative
> Groups,CN=name of Exchange Organization,CN=Microsoft Exchange,
> ' CN=Services,CN=Configuration,DC=xxxxxx,DC=xxx
> 'Set objIADSUser = GetObject("LDAP://CN="; & strCN & "," & strLDAPdn)
> 'objIADSUser.CreateMailbox ("LDAP://CN=AMBS3 (ROA-DC01),CN=Third Storage
> Group,CN=InformationStore,CN=ROA-DC01,CN=Servers,CN=First Administrative
> Group,CN=Administrative Groups,CN=yourdomain,CN=Microsoft
> Exchange,CN=Services,CN=Configuration,DC=yourdomain,DC=com")
>
> ' Set the user account objects home drive information in AD
> objUser.Put "homeDirectory", "\\" & strUserSrvr & "\" & strHomeFldr & "\"
> & LCase(strUser) & ""
> objUser.Put "homeDrive", "H"
>
> ' Create the user account objects home drive
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.CreateFolder("\\" & strUserSrvr & "\" & strHomeFldr
> & "\" & LCase(strUser))
> ' line 350
> ' Change the permissions on the user account objects home drive
> Set objShell = CreateObject("Wscript.Shell")
> strHome = "\\" & strUserSrvr & "\" & strHomeFldr & "\" & LCase(strUser)
> objShell.Run ("SetACL.exe -on """ & strHome & """ -ot file -actn ace " &
> "-ace ""n:yourdomain.com\" & strUser & ";p:change""")
>
> ' Create the user account objects public folder
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.CreateFolder("\\" & strUserSrvr & "\" &
> strPublicFldr & "\" & strPubFldrName)
> objUser.SetInfo
>
> Set objRootDSE = Nothing
> Set objOU = Nothing
> Set objUser = Nothing
> Set objGroup = Nothing
> Set objFSO = Nothing
> Set objFolder = Nothing
> Set objShell = Nothing
> Set objIADSUser = Nothing
>
> End Sub
>
> Sub Reload
> Location.Reload(True)
> End Sub
>
> Sub bodyLoaded()
> window.ResizeTo 600,510 ' WIDTH, HEIGHT
> End Sub
>
> </script>
> </head>
> <body onLoad="bodyLoaded()">
> <p align = "center"><img src="\\roa-dc01\images$\verisign.bmp" width="189"
> height="46"></p>
> <p align = "center" class="style2">User Account Object Creation Page.</p>
> <table width="289" border="0" align="left">
> <tr>
> <td width="89"><span class="style5">*</span>Login ID: </td>
> <td width="144"><input type="text" name="TextUser"></td>
> </tr>
> <tr>
> <td><span class="style5">*</span>First Name:</td>
> <td><input type="text" name="TextFirst"></td>
> </tr>
> <tr>
> <td>Middle Initial: </td>
> <td><input type="text" name="TextInitial"></td>
> </tr>
> <tr>
> <td><span class="style5">*</span>Last Name: </td>
> <td><input type="text" name="TextLast"></td>
> </tr>
> <tr>
> <td><span class="style5">*</span>Site: </td>
> <td align="left">
> <select size="1" name="Site">
> <option value="Roanoke">Roanoke</option>
> <option value="Richmond">Richmond</option>
> <option value="Blacksburg">Blacksburg</option>
> <option value="Raleigh">Raleigh</option>
> <option selected value="LocationAlert">-Select Users Location-</option>
> </select></td>
> <tr>
> <td><span class="style5">*</span>Mailbox: </td>
> <td align="left">
> <select size="1" name="MailBoxStore">
> <option value="AsstMBS1">Assistant 1</option>
> <option value="MngrMBS1">Manager 1</option>
> <option value="AsstMBS2">Assistant 2</option>
> <option value="MngrMBS2">Manager 2</option>
> <option value="AsstMBS3">Assitant 3</option>
> <option value="MngrMBS3">Manager 3</option>
> <option value="AsstMBS4">Assitant 4</option>
> <option value="MngrMBS4">Manager 4</option>
> <option selected value="LocationAlert">-Select Users Mail Box-</option>
> </select></td>
> </table>
> <p> </p>
> <p> </p>
>
> <p><br>
> <input type="button" name="Submit" value="Submit" onClick="CreateAccount">
> </p>
>
> <p>The new user account object will have an initial password of p@ssw0rd.
> </p>
> <p>The new employee will also be required to change his/her password at
> first logon. </p>
> <p class="style3"><span class="style6">*</span> Indicates Required
> Field</p>
> <br />
> <br />
> <br />
> <p>
> <input id="reloadbutton" class="button" type="reset" value="Clear Form"
> name="reload_button" onClick="Reload">
> </p>
> <p>
> <input type="button" value=" Exit " name="close_button"
> onClick="Self.Close">
> </p>
> </body>
> </html>
>
>
> Code ends here-------------------------
>
> Please feel free to use this as you see best. However, please use this in
> a test environment first and make sure that you make all of the
> modifications necessary so that it works in your environment. This works
> in a WIN2000 AD environment with Exchange 2000. Do not know if it would
> work in WIN2003 / Exchange 2003. I am not responsible for any damage that
> using this might cause. So, please figure everything out in a test lab'
> then use it in a production environment.
>
> If you do use this and make any changes to it or see something that could
> be better please let us know. This is a work in progress......
>
>
> --
> Cary W. Shultz
> Roanoke, VA 24012
>
> WIN2000 Active Directory MVP
> http://www.activedirectory-win2000.com
> (soon to be updated!!!)
> http://www.grouppolicy-win2000.com
> (soon to be updated!!!)
>
>
>
>


.


Quantcast