问题描述
我有一个脚本,可以让我在PC上隐藏文件夹(使用批处理文件).我刚刚为它实现了一个hta应用程序作为密码,因此更加安全.现在,我遇到的问题是,如果我想按Enter键在hta应用程序上提交表单,它将清除密码字段而什么也不做.我希望它具有与按确定"按钮相同的效果.这是我的批处理文件的hta部分:
I have a script that allows me to hide a folder on my pc (using batch file). I've just implemented an hta application to it for the password so It's more seccure. Now the problem I'm having is that if I want to press enter to submit the form on the hta application, it just clears the password field and does nothing. I would like it to have the same effect as if I were to push the OK button. This is the hta part of my batch file:
:HTA
<html>
<head>
<title>Password Entry</title>
<hta:application id="htaid"
applicationName="Password"
border="thin"
borderStyle="normal"
caption="yes"
contextMenu="no"
maximizeButton="no"
minimizeButton="yes"
navigable="yes"
showInTaskbar="yes"
singleInstance="yes"
sysmenu="yes"
version="0.1">
<script language="vbscript">
window.resizeTo 210, 110
Sub SaveBatch()
set fs=CreateObject("Scripting.FileSystemObject")
strFile=fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
set ts=fs.OpenTextFile(strFile, 2, True)
ts.WriteLine "set PASSWORD=" & document.Forms(0).elements("password").value
ts.Close
End Sub
</script>
</head>
<body>
<form style=margin-top:-15;>
Password:
<br><input type=password name=password>
<br><input type=button language="vbscript" value="OK" onclick="SaveBatch : Window.Close">
</form>
<script language=vbscript>
document.Forms(0).elements("password").focus
</script>
</body>
</html>
我尝试创建一种方法来检查onkeypress上的键码13,也尝试将其实现到password字段的html部分.它要么执行以前的操作,要么导致脚本错误.
I've tried creating a method that checks for keycode 13 onkeypress, also tried implementing it into the html portion of the password field. It either does what it did before, or causes a script error.
推荐答案
我刚刚写完了这批生成HTA BOX以便在CommandLine中隐藏密码的批处理,所以我想与您共享它!
I have just finished writing this batch that generate a HTA BOX to hide a password in CommandLine , so i want to share it with you !
如果喜欢的话,别忘了投票!
Don't forget to vote for it if you like it !
@echo off
Title Generate a HTA BOX to hide a password in CommandLine Copyright Hackoo 2014
mode con cols=80 lines=5 & color 9B
Set MyVBSFile=%tmp%\%~n0.vbs
Set MyHTAFile=%tmp%\%~n0.hta
Call :CreateMyVBS
Cscript.exe //NOLOGO %MyVBSFile%
start /wait mshta.exe "%MyHTAFile%"
Del "%MyVBSFile%" & Del "%MyHTAFile%"
for /f "tokens=*" %%i in (%tmp%\userIn) do set "Mypassword=%%i"
echo Your password is : %MyPassword%
Del %tmp%\userIn
pause
:#Start
<html>
<head>
<title>Password Entry</title>
<hta:application id="htaid"
applicationName="Password"
border="thin"
icon="wlrmdr.exe"
borderStyle="normal"
caption="yes"
contextMenu="no"
maximizeButton="no"
minimizeButton="yes"
navigable="yes"
showInTaskbar="yes"
singleInstance="yes"
sysmenu="yes"
SCROLL="NO"
SHOWINTASKBAR="Yes"
SELECTION="no"
MINIMIZEBUTTON="no"
>
</head>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<BODY TOPMARGIN="1" LEFTMARGIN="1"><CENTER><DIV><SPAN ID="ONSCR"></SPAN></DIV></CENTER></BODY>
<script language="vbscript">
'---------------------------------------------------------------------------------------
Sub Window_OnLoad
CenterWindow 250,150
Call PasswordForm()
Call TextFocus()
end sub
'---------------------------------------------------------------------------------------
Sub CenterWindow(x,y)
Dim iLeft,itop
window.resizeTo x,y
iLeft = window.screen.availWidth/2 - x/2
itop = window.screen.availHeight/2 - y/2
window.moveTo ileft,itop
End Sub
'----------------------------------------------------------------------------------------
Sub SaveBatch()
set fs=CreateObject("Scripting.FileSystemObject")
strFile=fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2),"UserIn"))
set ts=fs.OpenTextFile(strFile,2,True)
If PasswordArea.value <> "" Then
ts.WriteLine PasswordArea.value
ts.Close
self.Close 'To close this HTA after saving the password as a variable into UserIn.bat
else
Msgbox "The password entry is empty ! "& Vbcrlf & "Please type again your passowrd",VbExclamation,"The password entry"
Location.reload(true) 'To reload this HTA again
end if
End Sub
'----------------------------------------------------------------------------------------
Sub PasswordForm()
Self.document.title = "My Password Enrty"
Self.document.bgColor = "lightblue"
ONSCR.InnerHTML="<center><FONT COLOR=""#FFFFFF"" SIZE=""+1"" FACE=""VERDANA,ARIAL,HELVETICA,SANS-SERIF"">Password Entry</FONT<br>"_
&"<input type=""password"" name=""PasswordArea"" size=""20"" onKeyUp=""TextFocus""><P>"_
&"<input type=""Submit"" STYLE=""HEIGHT:25;WIDTH:110"" value=""OK"" onClick=""SaveBatch"">"
END Sub
'----------------------------------------------------------------------------------------
Sub TextFocus
PasswordArea.Focus
End Sub
'----------------------------------------------------------------------------------------
</script>
</body>
</html>
:#End
::***********************************************************************************************
:CreateMyVBS
::'**********************************************************************************************
(
echo. Set fso = CreateObject^("Scripting.FileSystemObject"^)
echo. Set f=fso.opentextfile^("%~f0",1^)
echo. a=f.readall
echo. Set r=new regexp
echo. r.pattern = "(?:^|(?:\r\n))(?::#Start\r\n)([\s\S]*?)(?:\r\n)(?::#End)"
echo. Set Matches = r.Execute^(a^)
echo. If Matches.Count ^> 0 Then Data = Matches^(0^).SubMatches^(0^)
echo. WriteFileText "%MyHTAFile%",Data
echo. f.close
::'**********************************************************************************************
echo.
echo. Function WriteFileText^(sFile,Data^)
echo. Dim objFSO,oTS,sText
echo. Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo. Set oTS = objFSO.CreateTextFile^(sFile,2^)
echo. oTS.WriteLine Data
echo. oTS.close
echo. set oTS = nothing
echo. Set objFSO = nothing
echo. End Function
) > %MyVBSFile%
::'***********************************************************************************************
这篇关于在HTA应用程序中按下Enter键时如何引起按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!