Hi folks,

Due to being unable to find a suitable app, i've decided to make a little app (with the help from my trusty DWeb chums)

Currently i'm looking at a little app that will allow me to enter a username and password for... whatever purpose really, map drive, shared folder etc etc etc"

I have found and modified a "hta" script that has a username and passwrod text entry field.

What i would like to add now is... after enterting the username and password and clicking the "run script" button, the script will verify the username and password entered with the one stored inside the script its self.
Then i want to add a modified vbs script into the hta script that will run a cmd prompt and perform the comand i want it to... Does that make sense :-)

its very nearly complete, however im just on the final streach now but cant seem to see where i need to go next...

Heres what we have so far in hta.

<head>
<title>Run Script</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Test"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>
 
<script language="VBScript">
 
Sub Window_onLoad
	intWidth = 400
	intHeight = 300
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
End Sub
 
Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_runscript.Click
	End If
End Sub

Sub RunScript

If Trim(txt_username.Value) = "" Then
		MsgBox "Please enter your username."
		txt_username.Focus
	ElseIf Trim(txt_password.Value) = "" Then
		MsgBox "Please enter your password."
		txt_password.Focus
	Else
		Set objShell = CreateObject("WScript.Shell")
		objShell.Run strCommand, 0, True

On Error Resume Next

	End If
End Sub
 
	
</script>
 
<body style="background-color:#B0C4DE; font-family: arial" onkeypress='vbs:Default_Buttons'>
	<table width='90%' height = '100%' align='center' border='0'>
		<tr>
			<td align='center'>
				<h2>Run Script</h2>
			</td>
		</tr>
		<tr>
			<td>
				User Name:<br>
				<input type="text" maxlength="30" size="40" id="txt_username" name="txt_username"><br><br>
			</td>
		</tr>
		<tr>
			<td>
				Pasword:<br>
				<input type="password" maxlength="30" size="40" id="txt_password" name="txt_password"><br><br>
			</td>
		</tr>
		<tr>
			<td align='center'>
				<input type="button" value="Run Script" name="btn_runscript"  onClick="vbs:RunScript">&nbsp&nbsp&nbsp&nbsp&nbsp
				<input type="button" value="Exit" name="btn_exit"  onClick="vbs:window.close"><br><br>
			</td>
		</tr>
	</table>
 
</body>


AND now THE VBS

Dim storedPassword
Password ="[I]testpassword1[/I]"

Dim storedusername
username ="[I]testusername1[/I]"

if entered password = Password Then
WScript.Echo "Correct"

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "[I]enter whaever command you want it to run after correct entry of details, here[/I]"

Else
WScript.Echo "Incorrect"
End if

So basically i want to merge these 2 files into 1 hta (glorified vbs) then i can sleep :-)

Thanks in advance if anyone can help... i'll keep plodding along as well

Phreak.

Update**

I've made a few ammendments and also found out from MSDN that even though the hta is a glorified vbs (vbs with support for html) the WScript.Shell etc command may not be supported.. Ho-hum

so here is the update... nearly there :-)

<head>
<title>testapp</title>
<HTA:APPLICATION
     APPLICATIONNAME="testapp"
     SCROLL="no"
     SINGLEINSTANCE="yes"
 >
</head>

<SCRIPT LANGUAGE="VBScript">

Sub Window_onLoad
	intWidth = 300
	intHeight = 200
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
End Sub

    Sub runcmdline
        On Error Resume Next
        Dim UserString, UserPassword, WshShell
        UserString = login.Value
        UserPassword = password.Value
        
        Set WshShell = CreateObject("WScript.Shell")
        WshShell.Run "ping or whatever"
	Set WshShell = Nothing
        'Clear the boxes now that we are done using the info
        login.Value =  ""
        password.Value =""
        UserString=Nothing
        UserPassword=Nothing                
    End Sub

</SCRIPT>


<body bgcolor="cyan"><center>
<h1>testapp</h1>
<table align="center">
<tr><td>Name:</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="2" align="center"><input id=runbutton  type="button" value="Go" name="run_button" onClick="runcmdline"></td></tr>
</td></tr>
</table>


<p>
<span id = "DataArea"></span>
</center></body>

So if i can get that "runcmdline" to actually run when the correct username and password are entered and the button is pressed ... then thats it done... and when the wrong details are entered and the button is pressed it just needs to throw bck a warning message and close.

:-)

feel free to chip in if anyone has any ideas on how to help,

Thanks in advance

Phreak

This can be tested by saving the text to a .hta and running. it just brings up a dialog box with login info anbd a go button. It has potential be moulded into virtually any app once complete...
I just need to find a way to add a static username and password in the script that when entered into the box it and matches it goes to the next line and run the cmd command. The vbs script posted works fine if the correct and or incorrect username and password are entered so i just need to implanment that into this and were off :-)

UPDATE ***


Right i have now got the vbs code running sucsessfully within the hta code :-)

What i have done so far is to create a functioning text entry box with a hidden/protected password entry text field (**********etc)

then i have told te hta to run the sub containing the vbs code only when the "GO" button is pressed.
This works perfectly, However, it will run the the vbs code when the button is pressed, no matter what you've enter into the text fields (if anything at all)...

We need to tell the "GO" button it to run the sub (vbs) ONLY when the text in both fields =

Username = "X"
Password = "Y"

If the above criteria is not met, to just close the application or throw back an error or whatever.

Ill edit the above posts to tidy things up a bit as well...

Keep your help coming, im struggeling with this final part...

Phreak

Edit... well i would tidy my posts up a bit if i could edit them :-)

This article has been dead for over six months. Start a new discussion instead.