我有一个脚本,允许我在我的pc上隐藏一个文件夹(使用批处理文件)。我刚刚为它实现了一个hta应用程序来获取密码,所以它更安全。现在我遇到的问题是,如果我想按enter键提交hta应用程序上的表单,它只是清除密码字段,什么也不做。我希望它有相同的效果,如果我按下OK按钮。这是我的批处理文件的hta部分:
: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>
我尝试创建一个方法来检查keycode 13 onkeypress,也尝试将其实现到密码字段的html部分。
试试我的修改代码,告诉我这是否奏效?
<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.bat"))
set ts=fs.OpenTextFile(strFile,2,True)
If PasswordArea.value <> "" Then
ts.WriteLine "set PASSWORD="& 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 = "#BBBFFF"
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>
我刚刚写完这批生成HTA BOX来隐藏命令行中的密码,所以我想和你分享一下!
如果你喜欢,别忘了给它投票!
@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 = "(?:^|(?:rn))(?::#Startrn)([sS]*?)(?:rn)(?::#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%
::'***********************************************************************************************