Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

HTA file - Clear password field when run...or even close window

Posted on 2011-03-09
9
622 Views
Last Modified: 2012-06-27
I found the HTA script somewhere on the Exchange that prompts for user and password to map a drive. I modified the HTA to ask for password only to mount a TrueCrypt volume. What I would like is for either the password field to reset when you click the Open Volume button...or better yet, close the window.  I am wondering if you can combine more than one thing to run at the "onClick=" for the button.

Thanks!
<head>
<title>Run Script</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Open Encrypted File"
     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

'Set 
Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_runscript.Click
	End If
End Sub
 
Sub RunScript
	If Trim(txt_password.Value) = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		strPassword = txt_password.Value
		
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run "c:\truecrypt.exe /v c:\testvol.100 /letter x: /auto /password " & strPassword

	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>Enter Encrypted File Password</h2>
			</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="Open Volume" 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>

Open in new window

0
Comment
Question by:BHForum
  • 4
  • 3
  • 2
9 Comments
 

Author Comment

by:BHForum
ID: 35086772
...one other thing. What would I need to do so that the password field has focus when the form is opened?

Thanks again!
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35087412
To give the password field focus:
Sub Window_onLoad
	intWidth = 400
	intHeight = 300
	Me.ResizeTo intWidth, intHeight
	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
        txt_password.Focus
End Sub

Open in new window


And to make it exit afterwards:
Sub RunScript
	If Trim(txt_password.Value) = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		strPassword = txt_password.Value
		
		Set objShell = CreateObject("WScript.Shell")
		objShell.Run "c:\truecrypt.exe /v c:\testvol.100 /letter x: /auto /password " & strPassword
                
		btn_exit.Click
	End If
End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35087433
Just to answer your other question, to clear the password box use:

    txt_password.Value = ""
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:BHForum
ID: 35088844
Idle_Mind:

Thanks. The focus works perfect but I get "Error: Object doesn't support this property or method: 'btn_exit.Click'"
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35088872
Hmm...I just copied and pasted your supplied code into a .txt file and renamed it .hta.  Then I simply added "btn_exit.Click" to that 'Else' block after commenting out the Run() line.  It correctly closed after clicking the button...

I'm running Win 7 Pro x64.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35088923
Instead of
            btn_exit.Click

just use
            window.close

Regards,

Rob.
0
 

Author Comment

by:BHForum
ID: 35089012
Got it. My bad. I did a copy paste to add another button and didn't change the button name. There were duplicate btn_exit names. Everything works perfectly.

Thanks a bunch!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35089027
Thanks for the post Rob...I'm definitely no HTA expert.  I assume that "window.close" would work no matter what since it doesn't rely on a specific button name?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35089120
Yes, that's right.  It can be called anywhere.

Rob.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question