Hi,
I have a HTA we use for new users. It create a home folder and add the
user to the right local group etc.
RMTSHARE.EXE and XCACLS.EXE is needed in the same folder as the HTA.
It works fine for us but instead of having a static list of groups i
want to enumerate the groups based on which server is choosed and add
the groups to the list in the drop-down box where i choose groups.
Any ideas on how to do this?
I made a Sub that enumerates the groups but i don't know how i could
get the result in the drop-down box.
________________________________________________________________________________________
<html>
<head>
<title>.:: Our ::. Add new user tool</title>
<HTA:APPLICATION
ID="Add_new_user_tool"
APPLICATIONNAME="Our Add new user tool"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximized"
</head>
<style>
BODY
{
background-color: buttonface;
font-family: Helvetica;
font-size: 12pt;
margin-top: 2px;
margin-left: 8px;
margin-right: 3px;
margin-bottom: 3px;
}
</style>
<SCRIPT language="VBScript">
on error resume next
Dim strServer
Dim strGroup
Dim strDomain
Dim strUser
Dim strHomeFolder
Dim s
Dim r
Dim fso
Dim f
Dim objShell
Dim objStdOut
Dim objFSO
Dim objUser
Dim objGroup
Sub Window_Onload
self.Focus()
self.ResizeTo 600,500
self.MoveTo 200,50
' Clear all variables in order for the
' "Enable Create button" IF statement to work
strServer = ""
strGroup = ""
strDepartment = ""
strUser = ""
End sub
Sub ServerSelectList
strServer = cboServerSelection.Value
' Enable Create button when all criteria is selected
If strServer <> "" and strUser <> "" and strGroup <> "" and
strDepartment <> "" Then Create_button.Disabled = False
spServer.InnerHTML = "Server where home folder will be created:" & " "
& strServer
End Sub
Sub UserButton
strUser = txtUserInput.Value
' Enable Create button when all criteria is selected
If strServer <> "" and strUser <> "" and strGroup <> "" and
strDepartment <> "" Then Create_button.Disabled = False
spUser.InnerHTML = "UserName will be added to group, also to be used
for home folder name:" & " " & strUser
End Sub
Sub GroupSelectList
strGroup = GroupSelection.Value
' Enable Create button when all criteria is selected
If strServer <> "" and strUser <> "" and strGroup <> "" and
strDepartment <> "" Then Create_button.Disabled = False
spGroup.InnerHTML = "Group where " & strUser & " will be added: " &
strServer & "\" & strGroup
End Sub
'Sub enumGroups
'strComputer = cboServerSelection.Value
'Set colGroups = GetObject("WinNT://" & strComputer & "")
'colGroups.Filter = Array("group")
'For Each objGroup In colGroups
' strGroup = objGroup.Name
'Next
'End Sub
Sub DepartmentSelectList
strDepartment = DepartmentSelection.Value
' Enable Create button when all criteria is selected
If strServer <> "" and strUser <> "" and strGroup <> "" and
strDepartment <> "" Then Create_button.Disabled = False
spDepartment.InnerHTML = "Home folder will be created in: " & "\\"&
strServer & "\d$\path\" & strDepartment & "\" & strUser
End Sub
Sub Create
' Add User to group
strDomain = "Domain"
Set objGroup = GetObject("WinNT://" & strServer & "/" & strGroup &
",group")
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser &
",user")
objGroup.Add(objUser.ADsPath)
' Create Home Folder
strHomeFolder = "\\" & strServer & "\d$\path\" & strDepartment & "\" &
strUser
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder(strHomeFolder)
' Share the folder
If FSO.FolderExists(strHomeFolder) Then
' Share the folder and assign rights.
strShare = " \\" & strServer & "\" & strUser & "$="
strSharePath = "d:\path\" & strDepartment & "\" & strUser
strGrant = " /GRANT " & strUser & ":change /GRANT administrators:f /
GRANT SYSTEM:f"
Set oShell = CreateObject("WScript.Shell")
intRunShareError = oShell.Run("%COMSPEC% /c Echo Y| RMTSHARE.EXE" &
strShare & strSharePath & strGrant, 0, True)
If intRunShareError <> 0 Then
MsgBox "Error creating share or asigning permissions for
user " _
& strUser & " to home folder " & strHomeFolder
Else
MsgBox "Home folder " & strHomeFolder & " is created and shared
as \\" & strServer & "\" & strUser & "$. User " & strUser & " is added
to " & strServer & "/" & strGroup & " !"
End If
End If
' Set permissions on the Home folder
If FSO.FolderExists(strHomeFolder) Then
' Assign user permission to home folder.
Set oShell = CreateObject("WScript.Shell")
intRunPermError = oShell.Run("%COMSPEC% /c Echo Y| xcacls " &
strHomeFolder & " /T /C /G Administrators:f SYSTEM:f " & strUser &
":C", 2, True)
If intRunPermError <> 0 Then
MsgBox "Error assigning permissions for user " _
& strUser & " to home folder " & strHomeFolder
End If
End If
' hide the folder from other users
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.GetFolder(strHomeFolder)
objFile.Attributes = objFile.Attributes + 2
' Disable Create Button
Create_button.Disabled=True
' Clear variables
strServer = ""
strGroup = ""
strUser = ""
strDepartment = ""
strDomain = ""
' Reset all text and list boxes
cboServerSelection.value = ""
txtUserInput.Value = ""
DepartmentSelection.value = ""
GroupSelection.value = ""
End Sub
' Cleanup
Set strServer = Nothing
Set strUser = Nothing
Set strGroup = Nothing
Set strDepartment = Nothing
Set strHomeFolder = Nothing
Set s = Nothing
Set r = Nothing
Set fso = Nothing
Set f = Nothing
Set sFILE = Nothing
Set objShell = Nothing
Set objWshScriptExec = Nothing
Set objStdOut = Nothing
Set objFSO = Nothing
</SCRIPT>
<body STYLE="
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#CCCCCC', EndColorStr='#FFFFFF')">
<H2 align="center">Add user to groups and create Home folder</H2>
<table border="0" cellpadding="0" cellspacing="0" style="width: 565px;
height: 104px">
<tr>
<td valign="top" style="height: 30px">
Select a server:</td>
<td valign="top" style="height: 30px">
Enter Username:</td>
</tr>
<tr>
<td valign="top" style="width: 281px; height: 30px;">
<select id="cboServerSelection" onChange="ServerSelectList"
name="ServerSelection" tabindex="1">
<option value="0"></option>
<option value="servername1">SERVERNAME1</option>
<option value="servername2">SERVERNAME2</option>
</select></td>
<td valign="top" style="width: 284px; height: 30px;">
<input type="text" id="txtUserInput" name="UserInput"
value="xxx0yyy" size="7" tabindex="2"/>
<button onclick="UserButton" name="SubmitUser" tabindex="3">Submit</
button></td>
</tr>
<tr>
<td valign="top" style="height: 30px">
Select a group:</td>
<td valign="top" style="height: 30px">
Select department:</td>
</tr>
<tr>
<td valign="top" style="width: 281px">
<select id="GroupSelection" onChange="GroupSelectList"
name="GroupSelection" tabindex="4">
<option value="0"></option>
<option value="group1"> GROUP1 </option>
<option value="group2"> GROUP2 </option>
<option value="group3"> GROUP3 </option>
<option value="group4"> GROUP4 </option>
</select></td>
<td valign="top" style="width: 284px">
<select
id="DepartmentSelection" onChange="DepartmentSelectList"
name="DepartmentSelection" tabindex="5">
<option value="0"></option>
<option value="ACCT">ACCT</option>
<option value="BD">BD</option>
<option value="HR">HR</option>
<option value="MKT">MKT</option>
<option value="PUBLIC">PUBLIC</option>
<option value="STAFF">STAFF</option>
<option value="Helpdesk">HELPDESK</option>
<option value="IT">IT</option>
</select></td>
</tr>
</table>
<p>
<hr>
<span id =spServer></span>
<p>
<span id =spUser></span>
<p>
<span id =spGroup></span>
<p>
<span id =spDepartment></span>
<hr>
<p align="left">
<input id=CreateButton class="button" type="button" value="Create"
name="Create_button" onClick="Create" Disabled=True tabindex="6">
</BODY>
</html>