Jump to content

Trying to create hta for AD accounts


Recommended Posts

Hi

I am not great at scripting and am running round trying to find things to modify and change to suit my purpose to allow our helpdesk to take over the function of initial account creation. I have been reading this thread intensely:

http://www.visualbasicscript.com/m_3296/mpage_8/key_/tm.htm

as it contains some of the things I am trying to do. Thing is, I could really do with pointers or specific articles on what I'm trying to achieve as I'm on a tight timeline.

This is what I have in the *.hta so far - I'm not too bothered about prettying it up at the moment:

<html> 
<HTA:APPLICATION
APPLICATIONNAME="Account Creation"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<head>
<title>User Account 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: #CC6600;
font-weight: bold;
}
.style5 {font-size: small; color: #FF0000; }
.style6 {color: #FF0000}
-->
</style>

<script type="text/vbscript">
Sub CreateAccount

strUser = TextBox0.Value
If strUser = "" Then
MsgBox "You're missing required fields.",64, "Alert"
Exit Sub
End If

strFirst = TextBox1.Value
If strFirst = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strInitial = TextBox2.Value

strLast = TextBox3.Value
If strLast = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strDisplay = strLast & ", " & strFirst

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<GC://dc=xalderhey,dc=com>;(&(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

Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

Set objOU = GetObject("LDAP://OU=Users - General,DC=xalderhey,DC=com")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.SetInfo

objUser.Put "givenName", strFirst

If strInitial <> "" Then
objUser.Put "initials", strInitial
End If

objUser.Put "sn", strLast
objUser.Put "displayName", strDisplay

objUser.SetPassword "password"
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

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><img src="c:\rlc_logo.gif" align=right></p>
<p class="style2">Account 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="textbox0"></td>
</tr>
<tr>
<td><span class="style5">*</span>First Name:</td>
<td><input type="text" name="textbox1"></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="textbox2"></td>
</tr>
<tr>
<td><span class="style5">*</span>Last Name: </td>
<td><input type="text" name="textbox3"></td>
</tr>
</table>

<p> </p>
<p> </p>
<p> </p>
<p><br>
<input type="button" name="Submit" value="Submit" onClick="CreateAccount">
</p>
<p>The login ID will have an initial password of password. </p>
<p>The new employee will also be required to change their password at first logon. </p>
<p class="style3"><span class="style6">*</span> Indicates Required Field</p>
<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>

What do I want to achieve next?

I would like another drop down menu with group membership that shows all the groups in my AD and allows you to choose one then upon clicking submit will allocate them to it. The only way I can see doing it is by populating a multi list box manually which I'd like to avoid and hook straight into AD if possible.

A tickbox to create an Exchange account on our mail server (MAIL01/Datastore x) in the format firstname.i.surname@domain.com

Create home profile folder and TS profile folder with appropriate permissions - I understand I have to use setACL but just haven't got this far yet

Add in other AD attributes like Department, Manager, Job Title, Telephone number and Address.

Can anyone provide me with some basic overview articles that goes through these steps please?

Link to comment
Share on other sites


Check out the Script repository in the Technet ScriptCenter

http://www.microsoft.com/technet/scriptcen...t.mspx?mfr=true

They have a large selection of Active Directory scripts to choose from. Though to do what you want with looking up the groups the machine you run this on will need to be a member of the domain. At least I have never found a reliable way to be off the domain and populate information about OU's & Groups.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...