I have written the script which helps to create a user in AD and set TS
properties. The scripts asks the hlepdek staff fee input like usernam,
firstname..etc.. but they are asking me to provide all the input box at
the same time
Firstname : |______________|
Lastname : |______________|
I did bit of reading about .hta files but I am a totally lost how to
get this up and running can someone shed some light on this?
here is my script
------------------------------------------------------------------------------------------------------------
dim retval 'integer
dim
server,UserName,homedir,homedrive,profilepath,homedirectory,objGroup2,objContainer
'string
dim bLogin 'boolean
Set fs = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fsOut =
fs.OpenTextFile("\\SYDPFNP01XX\NewUserCreation$\UserLogw2003.txt", 8,
True)
Set ou = GetObject("LDAP://OU=Dealer
Users,OU=Users,OU=TEST,DC=YYYYY,DC=com")
Username = InputBox( "Enter a user Name" )
If Username = "" Then
Msgbox "You cannot create a user without entering a username"
wscript.quit
Else
Wscript.echo Username
End If
FirstName = InputBox( "Enter the FirstName" )
LastName = InputBox( "Enter the user LastName" )
Role = InputBox( "Enter the user Description" )
Password = "P@55word1556a"
Wscript.sleep 500
on error resume next
Set objContainer = GetObject("LDAP://OU=Groups,OU=TEST,DC=YYYYYDC=COM")
set objGroup2 =
objContainer.GetObject("group","CN=AU-GL-XXXXX_Web_Users")
Set usr = ou.Create("user", "CN=" & FirstName & " " & LastName)
'--- Mandatory Attributes----
usr.Put "samAccountName", UserName
WScript.Sleep 500
'---- Optional Attributes, you can optionally skip these----
usr.Put "sn", LastName
usr.Put "givenName", FirstName
usr.Put "userPrincipalName", UserName & "@YYYYYY.COM"
usr.Put "title", Role
usr.Put "description", Role
usr.Put "displayName", FirstName & " " & LastName
usr.Put "pwdLastSet", CLng(0)
usr.SetInfo
WScript.Sleep 1000
usr.SetPassword Password
usr.AccountDisabled = False
usr.SetInfo
WScript.Sleep 1000
'--Now that the user is created, reset the user's password and
'--enable its account
'Enter Terminal Services Properties
'----------------------------------
usr.TerminalServicesProfilePath = "\\sydpfnp01XXXXX\Profiles$\" &
UserName
if (Err.Number <> 0 ) Then
fsout.writeline Err.Number & " TerminalServicesProfilePath " &
Err.Description
end if
err.clear
usr.SetInfo
usr.TerminalServicesHomeDrive = "P:"
if (Err.Number <> 0 ) Then
fsout.writeline Err.Number & " TerminalServicesHomeDrive " &
Err.Description
end if
err.clear
usr.SetInfo
usr.TerminalServicesHomeDirectory = "\\sydpfnp01XXXXX\Personal$\" &
UserName
if (Err.Number <> 0 ) Then
fsout.writeline Err.Number & " TerminalServicesHomeDirectory " &
Err.Description
end if
err.clear
usr.SetInfo
WScript.Sleep 1000
if (Err.Number <> 0 ) Then
fsout.writeline "There were some problems creating the user " &
UserName & ". Please Check if the user Exists in AD and the user CSV
settings: " & UserName & ", " & FirstLast
end if
err.clear
'Adding user to the group
'-------------------------------
objGroup2.Add(usr.ADsPath)
if (Err.Number <> 0 ) Then
fsout.writeline "Can not add user to group AU-GL-XXXXX_Web_Users"
end If
err.clear
WScript.Sleep 1000
'creating Home Directory
'-------------------------------
Set newfolder = fs.CreateFolder("\\\\sydpfnp01XXXXX\personal$\" &
UserName)
WScript.Sleep 1000
SetFolderSecurity = WshShell.Run("cacls \\\\sydpfnp01XXXXX\personal$\"
& UserName & " /T /E /G """ & UserName & """:F /R Everyone")
SetFolderSecurity = WshShell.Run("cacls \\\\sydpfnp01XXXXX\personal$\"
& UserName & " /T /E /G ""GEADPHOENIX\AU-GL-TEST_App_Support"":F /R
Everyone")
SetFolderSecurity = WshShell.Run("cacls \\\\sydpfnp01XXXXX\personal$\"
& UserName & " /T /E /G ""GEADPHOENIX\AU-GL-TEST__System_Admin"":F /R
Everyone")
SetFolderSecurity = WshShell.Run("cacls \\\\sydpfnp01XXXXX\personal$\"
& UserName & " /T /E /G Administrators:F /R Everyone")
'**************************************************************
Wscript.echo "User account has been created. "
WATCH FOR LINE WRAP !!!!!!
Then you can use the Split function to get what you need
strUserInput = InputBox("Please enter your Firstname, Lastname - COMMA is
required", "Enter user Info, "FirstName,LastName")
ss = Split strUserInput(strUsrInput, ",", -1, 1) ' Note, comma is default
seperator, you can leave that out if you like.
WScript.Echo "Firstname : " & ss(0)
WScript.Echo "LastName : " & ss(1)
If you want fancy, here is a bit of code to get the input from IE.
I stripped this out of a very large script I wrote that get about 15
inputs from the user via IE so I hope I have not left anyting out.
I do not run this from and HTA as there is nothing here that triggers
the IE security, I run it straight from a vbs.
TDM
Dim objUsrOptionsApp
Dim objUsrOptions
Dim objIeOptions
Dim strIeOptFirstName
Dim strIeOptLastName
Dim bCancel
Call genOptionsPage()
' Wait for the user to do something, submit the options page or bail.
Do While Not bGotOptions
objIeOptions.Item("Submit").Onclick = GetRef("getOptions")
objIeOptions.Item("Cancel").Onclick = GetRef("optCancel")
WScript.Sleep 100
Loop
If bCancel Then
WScript.Echo "User cancelled out, no information provided ..."
Else
WScript.Echo "First Name : " & strIeOptFirstName
WScript.Echo "Last Name : " & strIeOptLastName
End If
WScript.Quit
Function genOptionsPage()
' This function does nothing more than build the options web page.
Set objUsrOptionsApp = WScript.CreateObject("InternetExplorer.Application")
With objUsrOptionsApp
.ToolBar = False
.TheaterMode = False
.StatusBar = False
.Resizable = True
.Visible = True
.Height = 260
.Width = 760
.Navigate("about:blank")
.Left = .Document.ParentWindow.Screen.Width / 2 - .Width / 2
.Top = .Document.ParentWindow.Screen.Height / 2 - .Height / 2
Set objUsrOptions = .Document
End With
With objUsrOptions
.ParentWindow.Document.Body.Style.BorderStyle = "Dotted"
.ParentWindow.Document.Body.Scroll = "Auto"
.WriteLn("<HTML>")
.WriteLn("<TITLE>User Information Input</TITLE>")
.WriteLn("<FORM NAME=""optionForm"">")
.WriteLn("<BODY BGCOLOR=""#FFFFFF"" ONLOAD=""setFocus()""></BODY>")
.WriteLn("<FONT Face=""Verdana""><H4>Please enter the REQUIRED
information</H4></FONT>")
.WriteLn("<DIV ALIGN=""Left"">")
.WriteLn("<TABLE cellpadding=""2"" width=""700px""
align=""Center""><TBODY>")
.WriteLn("<tr><td Colspan=""2""><hr align=""Center"" size=""2""
width=""100%"" color=""#000000""><table cellpadding=""2""></td></tr>")
.WriteLn("<TR><TD><FONT Face=""Verdana"" Size=""1"">Enter User
Information</FONT></TD></TR>")
.WriteLn("<TR><TD Colspan=""2""><hr align=""Center"" size=""2""
width=""100%"" color=""#000000""></TD></TR>")
.WriteLn("<TR><TD><FONT COLOR=""Blue"" Size=""1"" FACE=""Verdana"">First
Name </FONT><INPUT TYPE=""Text"" TABINDEX=""1"" ALIGN=""Center""
NAME=""firstName"" SIZE=""16""></FONT></TD>")
.WriteLn("<TD><FONT COLOR=""Blue"" Size=""1"" FACE=""Verdana"">Last Name
</FONT><INPUT TYPE=""Text"" TABINDEX=""2"" ALIGN=""Center""
NAME=""lastName"" SIZE=""16""></TD></TR></TBODY></TABLE>")
.WriteLn("<hr align=""left"" size=""2"" width=""100%"" color=""#000000"">")
.WriteLn("<TABLE Width=""100%""><TBODY><TR><TD align=""center""><INPUT
TYPE=""Button"" TABINDEX=""3"" ALIGN=""Center"" NAME=""Submit""
VALUE=""Submit Options"" ONCLICK='getOptions()'></TD>")
.WriteLn("<TD align=""left""><INPUT TYPE=""Button"" TABINDEX=""4""
ALIGN=""Center"" NAME=""Cancel"" VALUE=""Cancel""
ONCLICK='optCancel()'></TD></TR></TBODY></TABLE>")
.WriteLn("<SCRIPT Language=""JavaScript"" TYPE=""text/javascript"">")
.WriteLn("function setFocus(){")
.WriteLn("this.document.optionForm.firstName.focus();")
.WriteLn("}")
.WriteLn("</SCRIPT>")
.WriteLn("</DIV>")
.WriteLn("</FONT>")
.WriteLn("</FORM>")
.WriteLn("</HTML>")
.Close
Set objIeOptions = objUsrOptions.All
End With
End Function
Function getOptions()
' This function is called when the user hits the submit button on the
' options page.
strIeOptFirstName = objIeOptions.Item("firstName").Value
strIeOptLastName = objIeOptions.Item("lastName").Value
bGotOptions = True
objUsrOptionsApp.Quit
Set objUsrOptionsApp = Nothing
End Function
Function optCancel()
' This function is called when the user hits the cancel button on the
' options page.
bCancel = True
bGotOptions = True
objUsrOptionsApp.Quit
Set objUsrOptionsApp = Nothing
End Function
<jap...@yahoo.com> wrote in message
news:1156222859.8...@m79g2000cwm.googlegroups.com...
strUserInput = InputBox("Please enter your Firstname, Lastname - COMMA is
required", "Enter user Info", "FirstName,LastName")
TDM
"TDM" <rpu...@gmail.com> wrote in message
news:eJ9KF2f...@TK2MSFTNGP06.phx.gbl...
Thanks mate ..it looks pretty good but where should I implement my
script? I am not sure where my script to be placed.
Also is there a theory which explains when we need to choose hta?
Thanks
cha
First, watch for LINE WRAP.
A quick look at your script and I find 4 InputBox's. I would
replace alll this :
>> > Username = InputBox( "Enter a user Name" )
>> > If Username = "" Then
>> > Msgbox "You cannot create a user without entering a username"
>> > wscript.quit
>> > Else
>> > Wscript.echo Username
>> > End If
>> >
>> >
>> > FirstName = InputBox( "Enter the FirstName" )
>> > LastName = InputBox( "Enter the user LastName" )
>> > Role = InputBox( "Enter the user Description" )
With this :
Call genOptionsPage()
' Wait for the user to do something, submit the options page or bail.
Do While Not bGotOptions
objIeOptions.Item("Submit").Onclick = GetRef("getOptions")
objIeOptions.Item("Cancel").Onclick = GetRef("optCancel")
WScript.Sleep 100
Loop
If bCancel Then
WScript.Echo "User cancelled out, no information provided ..."
WScript.Quit
ElseIf strIeUserName = "" Then
WScript.Echo "You cannot create a user without entering a UserName, please
try again ..."
WScript.Quit
Else
WScript.Echo "First Name : " & strIeOptFirstName
WScript.Echo "Last Name : " & strIeOptLastName
WScript.Echo "User Name : " & strIeUserName
WScript.Echo "User Role : " & strIeRole
End If
Declare these variables globally at the top of your script, although not
necessary
without Option Explicit, I always declare variables :
Dim objUsrOptionsApp
Dim objUsrOptions
Dim objIeOptions
Dim strIeUserName
Dim strIeRole
Dim strIeOptFirstName
Dim strIeOptLastName
Dim bCancel
Then, add these functions to the end of your script :
****************************************************************
Function genOptionsPage()
' This function does nothing more than build the options web page.
Set objUsrOptionsApp = WScript.CreateObject("InternetExplorer.Application")
With objUsrOptionsApp
.ToolBar = False
.TheaterMode = False
.StatusBar = False
.Resizable = True
.Visible = True
.Height = 300
.WriteLn("<TR><TD><FONT COLOR=""Blue"" Size=""1"" FACE=""Verdana"">User
Name </FONT><INPUT TYPE=""Text"" TABINDEX=""3"" ALIGN=""Center""
NAME=""userName"" SIZE=""16""></FONT></TD>")
.WriteLn("<TD><FONT COLOR=""Blue"" Size=""1"" FACE=""Verdana"">User Role
</FONT><INPUT TYPE=""Text"" TABINDEX=""4"" ALIGN=""Center"" NAME=""role""
SIZE=""16""></TD></TR></TBODY></TABLE>")
.WriteLn("<TR><TD><p></p></TD></TR>")
.WriteLn("<TABLE Width=""100%""><TBODY><TR><TD align=""center""><INPUT
TYPE=""Button"" TABINDEX=""5"" ALIGN=""Center"" NAME=""Submit""
VALUE=""Submit Options"" ONCLICK='getOptions()'></TD>")
.WriteLn("<TD align=""left""><INPUT TYPE=""Button"" TABINDEX=""6""
ALIGN=""Center"" NAME=""Cancel"" VALUE=""Cancel""
ONCLICK='optCancel()'></TD></TR></TBODY></TABLE>")
.WriteLn("<SCRIPT Language=""JavaScript"" TYPE=""text/javascript"">")
.WriteLn("function setFocus(){")
.WriteLn("this.document.optionForm.firstName.focus();")
.WriteLn("}")
.WriteLn("</SCRIPT>")
.WriteLn("</DIV>")
.WriteLn("</FONT>")
.WriteLn("</FORM>")
.WriteLn("</HTML>")
.Close
Set objIeOptions = objUsrOptions.All
End With
End Function
Function getOptions()
' This function is called when the user hits the submit button on the
' options page.
strIeOptFirstName = objIeOptions.Item("firstName").Value
strIeOptLastName = objIeOptions.Item("lastName").Value
strIeUserName = objIeOptions.Item("userName").Value
strIeRole = objIeOptions.Item("role").Value
bGotOptions = True
objUsrOptionsApp.Quit
Set objUsrOptionsApp = Nothing
End Function
Function optCancel()
' This function is called when the user hits the cancel button on the
' options page.
bCancel = True
bGotOptions = True
objUsrOptionsApp.Quit
Set objUsrOptionsApp = Nothing
End Function
*******************************************************
I did test this and it seems to work OK, but you be the judge.
As for "Theory" on HTA, I have not found any per say. But, it is my
understanding that you would use an HTA any time it you would be
triggering IE security, like accessing files, using ActiveX controls, or
accessing the Registry. I actually have only implemented an HTA
once as most of my scripts are designed to be command line run.
If these scripts use IE, lets say to grab a bunch of input from the
user all at once, then I test the IE security settings in advance and
act accordingly. In reality, an HTA would be a much better solution
but I just have not found the time to convert them.
I also use IE to provide dialog to the user as a script is running
so they know something is happening, in this case, no IE security is
being tested so there is no need for an HTA or to test security
settings.
Hope this helps in some way.
TDM