Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.HTA subroutine not passing text after space 1

Status
Not open for further replies.

Dbyte

Technical User
Mar 6, 2002
87
0
0
Goal: a .hta page that will allow users to reset the password only for users within their dept & email IT to notify that it was done.
Problem: UserList.value in Sub ResetPassword does not include any characters after the space between first & last names. So in testing the name "Jane Smith" shows as only "Jane".

I need a way to grab the whole displayName (or other unique value like samAccountName) from the selection list so that I can reset the correct password & have it displayed correctly in the email body. Here is my code so far:
Code:
<head>
<title>WINDOWS PASSWORD RESET</title>
<HTA:APPLICATION 
	APPLICATIONNAME="Windows Password Reset"
    SCROLL="no"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="normal"
	MaximizeButton="no"
	MinimizeButton="no"
	SysMenu="yes"
	Caption="yes"
	Border="thick"
>
</head>

<script language="VBScript">
	Sub Window_onLoad
		window.resizeTo 300,400
		Set oSysInfo = CreateObject("ADSystemInfo")
		sUser = oSysInfo.UserName
		Set oUser = GetObject("LDAP://" & sUser)
		NameArea.InnerHTML = "Current user is:  <strong>" & oUser.displayName & "</strong>"
		sADString = oUser.parent
		Const ADS_SCOPE_SUBTREE = 2
		Set oConn = CreateObject("ADODB.Connection")
		Set oCommand =   CreateObject("ADODB.Command")
		sHTML = "<select size=""10"" name=""UserList"">"
		oConn.Provider = "ADsDSOObject"
		oConn.Open "Active Directory Provider"
		Set oCommand.ActiveConnection = oConn
		oCommand.Properties("Page Size") = 1000
		oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
		oCommand.CommandText = "SELECT displayName FROM '" & sADString & "' WHERE objectCategory='user'"
		Set oRecordSet = oCommand.Execute
		Dim arrNames()
		iSize = 0
		Do Until oRecordSet.EOF
		    ReDim Preserve arrNames(iSize)
    		arrNames(iSize) = oRecordSet.Fields("displayName").value
			iSize = iSize + 1
		    oRecordSet.MoveNext
		Loop
		For i = (UBound(arrNames) - 1) to 0 Step -1
    		For j= 0 to i
        		If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
            	   sHolder = arrNames(j+1)
            	   arrNames(j+1) = arrNames(j)
            	   arrNames(j) = sHolder
        		End If
    		Next
		Next
		For Each sName in arrNames
    		sHTML = sHTML & "<option value=" & sName & ">" & sName & "</option>"
		Next
		sHTML = sHTML & "</select>"
		FromUser.InnerHTML = sHTML
	End Sub
	Sub ResetPassword
                Set oUser = UserList.value		
                oUser.SetPassword("DEFAULT")
		Set oSysInfo = CreateObject("ADSystemInfo")
		sUser = oSysInfo.UserName
		Set oUser = GetObject("LDAP://" & sUser)
		Set WshNetwork = CreateObject("WScript.Network")
		sPC = WshNetwork.ComputerName
   		sFrom = "email@somesite.com"
   		sTo = "email2@somesite.com"
   		sSub = "Password Reset"
   		sBody = oUser.displayName & " reset the password of " & UserList.value & " @ " & Time & " from " & sPC
   		sSMTP = "192.168.1.1"
		set oEmail = CreateObject("CDO.Message")
   		oEmail.From = sFrom
   		oEmail.To = sTo
   		oEmail.Subject = sSub
   		oEmail.Textbody = sBody
   		oEmail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
   		oEmail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = sSMTP
   		oEmail.Configuration.Fields.Update
   		oEmail.Send
	End Sub
</script>

<body bgcolor='#f2e8d2'>
<font face="arial, verdana, helvetica">
<center><span id="NameArea"></span></center>
<p>
<hr color="#006600" size="2" width="90%" noshade>
<p>
Please select a user below:
<center><span id="FromUser"></span></center>
<br><br>
<center><input type="button" value="Reset User's Password" name="run_button" onClick="ResetPassword"></center>
</font>
</body>

Right now my email body looks like:
"John Smith reset the password of Jane @ 9:21:55 AM from PC09001
 
Have you tried this ?
Code:
sHTML = sHTML & "<option value=[!]'[/!]" & sName & "[!]'[/!]>" & sName & "</option>"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Worked perfectly PHV - thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top