當您想要隱藏用戶輸入的密碼的條目並且可以將其作爲變量供以後使用時,我提供了一個用於批處理的新元素。 所以,這個程序是一個混合了腳本Batch,VBScript和HTA的混合。
HTAPASSWORDBOX.bat
@echo off
Title G‚n‚rer un HTABOX pour cacher un mot de passe en ligne de commande Copyright Hackoo 2014
mode con cols=90 lines=3 & color 9B
Set MyVBSFile=%tmp%\%~n0.vbs
Set MyHTAFile=%tmp%\%~n0.hta
:: Créer le VBS Pour extraire et générer le code du HTA
Call :CreateMyVBS
:: Lancer Le VBS
Cscript.exe //NOLOGO %MyVBSFile%
:: Lancer Le HTA crée par le VBS
start /wait mshta.exe "%MyHTAFile%"
Del "%MyVBSFile%" & Del "%MyHTAFile%"
:: Lire le contenu du fichier %tmp%\userIn pour extraire le mot de passe tapé depuis
:: le HTABOX et le définir comme une variable
for /f %%i in (%tmp%\userIn) do set "Mypassword=%%i"
echo Votre mot de passe saisi est : %MyPassword%
Del %tmp%\userIn
pause
Exit /b
:#Start
<html>
<head>
<title>Mot de Passe © Hackoo</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 300,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 SavePassword()
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 'Pour fermer ce HTA après avoir enregistré le mot de passe comme une variable dans le fichier Userin
else
Msgbox "Le mot de passe est vide ! "& Vbcrlf & "SVP entrez de nouveau votre mot de passe",VbExclamation,"Mot de Passe © Hackoo"
Location.reload(true) 'Pour recharger à nouveau ce HTA
end if
End Sub
'----------------------------------------------------------------------------------------
Sub PasswordForm()
Self.document.title = "Mot de Passe © Hackoo"
Self.document.bgColor = "lightblue"
ONSCR.InnerHTML="<center><FONT COLOR=""#FFFFFF"" SIZE=""+1"" FACE=""VERDANA,ARIAL,HELVETICA,SANS-SERIF"">Taper votre mot de passe</FONT<br>"_
&"<input type=""password"" name=""PasswordArea"" size=""20"" onKeyUp=""TextFocus""><P>"_
&"<input type=""Submit"" STYLE=""HEIGHT:25;WIDTH:110"" value=""OK"" onClick=""SavePassword"">"
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%
::'***********************************************************************************************
我做了一個非常愚蠢的錯誤!謝謝! – 2014-10-29 12:13:09