Return 从 HTA 到打开它的 VBS 脚本的表单输入值
Return form input values from an HTA to a VBS script that opened it
我有一个映射驱动器的 VBS 脚本。根据用户的不同,可以映射通用文件夹(不需要凭据)或个人文件夹(需要用户名和密码)。我目前为此使用标准的 WSH 输入,这显然不太安全,因为密码未被屏蔽
我已经查看了使用 ScriptPW.dll
的解决方案,但这不再是 Windows 的原生解决方案(我使用的是 Windows 7)并且在复制时不起作用来自 XP 并已注册。
我现在正在考虑的一种解决方案是使用 HTA 来提示输入 username/password。我已经到了 运行 需要文件的地步,但我不确定如何(或者即使我可以) return 从表单到父级的输入值脚本。
这可能吗?
注意 - 由于表格并非在所有情况下都需要,因此我无法将整个脚本放在 HTA 中。
这是我给 HTA 打电话的方式 -
Dim Shell
Set Shell = Wscript.CreateObject("Wscript.Shell")
Shell.Run("test.hta"), 1, True
Set Shell = Nothing
这是 HTA -
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Login Application</title>
<hta :application
applicationname="LoginBox"
border="dialog"
borderstyle="normal"
caption="My HTML Application"
contextmenu="no"
maximizebutton="no"
minimizebutton="yes"
navigable="no"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal" />
</head>
<body>
<form id="LoginForm">
Enter Username: <input type="textbox" id="UserName"/><br />
Enter Password: <input type="password" id="Password"/><br />
<input type="submit" value="Open my scans"/>
</form>
</body>
</html>
我觉得这个功能密码框可以帮到你,试试吧;)
' Just an example of how to use the function
'
wsh.echo "You entered: ", _
Join(PasswordBox("Enter UID and password", _
"Testing"), ", ")
' A function to present a Password dialog in a VBS (WSF)
' script
' Requires WScript version 5.1+
' Tom Lavedas <tlavedas@hotmail.com>
' with help from and thanks to Joe Ernest and
' Michael Harris
'
' modified 1/2008 to handle IE7
'
Function PasswordBox(sPrompt,sDefault)
set oIE = CreateObject("InternetExplorer.Application")
With oIE
' Configure the IE window
.RegisterAsDropTarget = False
.statusbar = false : .toolbar = false
.menubar = false : .addressbar = false
.Resizable = False
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
' Test for IE 7 - cannot remove 'chrome' in that version
sVersion = .document.parentWindow.navigator.appVersion
if instr(sVersion, "MSIE 7.0") = 0 Then .FullScreen = True
.width = 400 : .height = 270
' Create the password box document
With .document
oIE.left = .parentWindow.screen.width \ 2 - 200
oIE.top = .parentWindow.screen.height\ 2 - 100
.open
.write "<html><head><" & "script>bboxwait=true;</" _
& "script><title>Password _</title></head>"_
& "<body bgColor=silver scroll=no " _
& "language=vbs style='border-" _
& "style:outset;border-Width:3px'" _
& " onHelp='window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " oncontextmenu=" _
& "'window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " onkeydown='if ((window.event.keycode>111)"_
& " and (window.event.keycode<117)) or" _
& " window.event.ctrlkey then" _
& " window.event.keycode=0" _
& ":window.event.cancelbubble=true" _
& ":window.event.returnvalue=false'" _
& " onkeypress='if window.event.keycode=13" _
& " then bboxwait=false'><center>" _
& "<div style='padding:10px;background-color:lightblue'>" _
& "<b> " & sPrompt & "<b> </div><p>" _
& "<table bgcolor=cornsilk cellspacing=10><tr><td>" _
& " <b>User:</b></td><td>" _
& "<input type=text size=10 id=user value='" _
& sDefault & "'>" _
& "</td><tr><td> <b>Password:</b></td><td>" _
& "<input type=password size=12 id=pass>" _
& "</td></tr></table><br>" _
& "<button onclick='bboxwait=false;'>" _
& " Okay " _
& "</button> <button onclick=" _
& "'document.all.user.value=""CANCELLED"";" _
& "document.all.pass.value="""";" _
& "bboxwait=false;'>Cancel" _
& "</button></center></body></html>"
.close
Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop
.all.user.focus
.all.user.select ' Optional
oIE.Visible = True
CreateObject("Wscript.Shell")_
.Appactivate "Password _"
PasswordBox = Array("CANCELLED")
On Error Resume Next
Do While .parentWindow.bBoxWait
if Err Then Exit Function
WScript.Sleep 100
Loop
oIE.Visible = False
PasswordBox = Array(.all.user.value, _
.all.pass.value)
End With ' document
End With ' IE
End Function
我有一个映射驱动器的 VBS 脚本。根据用户的不同,可以映射通用文件夹(不需要凭据)或个人文件夹(需要用户名和密码)。我目前为此使用标准的 WSH 输入,这显然不太安全,因为密码未被屏蔽
我已经查看了使用 ScriptPW.dll
的解决方案,但这不再是 Windows 的原生解决方案(我使用的是 Windows 7)并且在复制时不起作用来自 XP 并已注册。
我现在正在考虑的一种解决方案是使用 HTA 来提示输入 username/password。我已经到了 运行 需要文件的地步,但我不确定如何(或者即使我可以) return 从表单到父级的输入值脚本。
这可能吗?
注意 - 由于表格并非在所有情况下都需要,因此我无法将整个脚本放在 HTA 中。
这是我给 HTA 打电话的方式 -
Dim Shell
Set Shell = Wscript.CreateObject("Wscript.Shell")
Shell.Run("test.hta"), 1, True
Set Shell = Nothing
这是 HTA -
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Login Application</title>
<hta :application
applicationname="LoginBox"
border="dialog"
borderstyle="normal"
caption="My HTML Application"
contextmenu="no"
maximizebutton="no"
minimizebutton="yes"
navigable="no"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal" />
</head>
<body>
<form id="LoginForm">
Enter Username: <input type="textbox" id="UserName"/><br />
Enter Password: <input type="password" id="Password"/><br />
<input type="submit" value="Open my scans"/>
</form>
</body>
</html>
我觉得这个功能密码框可以帮到你,试试吧;)
' Just an example of how to use the function
'
wsh.echo "You entered: ", _
Join(PasswordBox("Enter UID and password", _
"Testing"), ", ")
' A function to present a Password dialog in a VBS (WSF)
' script
' Requires WScript version 5.1+
' Tom Lavedas <tlavedas@hotmail.com>
' with help from and thanks to Joe Ernest and
' Michael Harris
'
' modified 1/2008 to handle IE7
'
Function PasswordBox(sPrompt,sDefault)
set oIE = CreateObject("InternetExplorer.Application")
With oIE
' Configure the IE window
.RegisterAsDropTarget = False
.statusbar = false : .toolbar = false
.menubar = false : .addressbar = false
.Resizable = False
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
' Test for IE 7 - cannot remove 'chrome' in that version
sVersion = .document.parentWindow.navigator.appVersion
if instr(sVersion, "MSIE 7.0") = 0 Then .FullScreen = True
.width = 400 : .height = 270
' Create the password box document
With .document
oIE.left = .parentWindow.screen.width \ 2 - 200
oIE.top = .parentWindow.screen.height\ 2 - 100
.open
.write "<html><head><" & "script>bboxwait=true;</" _
& "script><title>Password _</title></head>"_
& "<body bgColor=silver scroll=no " _
& "language=vbs style='border-" _
& "style:outset;border-Width:3px'" _
& " onHelp='window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " oncontextmenu=" _
& "'window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " onkeydown='if ((window.event.keycode>111)"_
& " and (window.event.keycode<117)) or" _
& " window.event.ctrlkey then" _
& " window.event.keycode=0" _
& ":window.event.cancelbubble=true" _
& ":window.event.returnvalue=false'" _
& " onkeypress='if window.event.keycode=13" _
& " then bboxwait=false'><center>" _
& "<div style='padding:10px;background-color:lightblue'>" _
& "<b> " & sPrompt & "<b> </div><p>" _
& "<table bgcolor=cornsilk cellspacing=10><tr><td>" _
& " <b>User:</b></td><td>" _
& "<input type=text size=10 id=user value='" _
& sDefault & "'>" _
& "</td><tr><td> <b>Password:</b></td><td>" _
& "<input type=password size=12 id=pass>" _
& "</td></tr></table><br>" _
& "<button onclick='bboxwait=false;'>" _
& " Okay " _
& "</button> <button onclick=" _
& "'document.all.user.value=""CANCELLED"";" _
& "document.all.pass.value="""";" _
& "bboxwait=false;'>Cancel" _
& "</button></center></body></html>"
.close
Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop
.all.user.focus
.all.user.select ' Optional
oIE.Visible = True
CreateObject("Wscript.Shell")_
.Appactivate "Password _"
PasswordBox = Array("CANCELLED")
On Error Resume Next
Do While .parentWindow.bBoxWait
if Err Then Exit Function
WScript.Sleep 100
Loop
oIE.Visible = False
PasswordBox = Array(.all.user.value, _
.all.pass.value)
End With ' document
End With ' IE
End Function