Monday, August 14, 2006

Using HTA to Hide Credentials

This is an example of a recent HTA I created for starting a script using alternate credentials. Service desk staff often need to run scripts using support accounts that they are not logged on to as standard. This HTA provides a simple way to hide the input of credentials and pass it as arguments to a script or it could be used to launch a script using runas.

<head>
<title>Provide Credentials</title>
<HTA:APPLICATION
APPLICATIONNAME="HTALogin"
SCROLL="no"
SINGLEINSTANCE="yes">
</head>

<SCRIPT LANGUAGE="VBScript">

Sub Window_onLoad
window.resizeTo 500,250
End Sub

Sub Runscript
On Error Resume Next
Dim UserString, UserPassword, WSHNetwork
UserString = login.Value
UserPassword = password.Value
Set objshell = CreateObject("WScript.Shell")
objshell.run "cscript test.vbs /user:"" & UserString & ""/pwd:""& UserPassword"
'Clear the boxes now that we are done using the info
login.Value = ""
password.Value =""
UserString=Nothing
UserPassword=Nothing
End Sub

</SCRIPT>

<body STYLE="font:14 pt arial; color:white; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=1, StartColorStr='#000000', EndColorStr='#0000FF')">
<h1>Provide Credetials</h1>
<table align="center">
<tr><td>Username:</td><td><input type="text" name="login" size="30"></td></tr>
<tr><td>Pasword:</td><td><input type="password" name="password" size="30"></td></tr>
<tr><td colspan="1" align="center"><input id=runbutton type="button" value="Run Script" name="run_button" onClick="Runscript"></td></tr>
</td></tr>
</table>
<p>
<span id = "DataArea"></span></center></body>


Dave