如何从vbscript中获取往返HTA的变量
更新:我找出了我第一个问题的答案。实际上,我使用了两种方法。对于“ strboxtitle”变量,我替换了该行:
<b>strBoxTitle</b><p>
正确
<b>
<script>document.write( strBoxTitle )</script>
</b><p>
显示了变量的值,而不是其名称。但是,这对“ strlocaluser”变量不起作用,因为它在输入标签内。对于那个,我将行添加
document.getElementById("userid").value = strLocalUser
到我的window_onload函数中,然后将输入标签更改为
<input id='userid' size=20 class='fixed' value=strLocalUser>
也
<input id='userid' size=20 class='fixed'>
有效的,并以“ strlocaluser”的值填充了用户输入字段,更不用说阻止我需要嵌套脚本在输入标签中标记,显然不允许使用。
原始问题:
我正在尝试编写一个从vbscript文件调用的HTA文件以获取用户输入。我用命令将HTA文件调用
objWShell.Run ".\UserInput.hta | " & "Please Enter Your Credentials" & _
" | " & strLoginID,1,True
hta文件“ userInput.hta”,我在堆栈溢出中写下了以下示例,是
<!DOCTYPE html>
<html>
<head>
<hta:application
id = oHTA
border = dialog
innerborder = no
caption = yes
sysmenu = no
maximizebutton = no
minimizebutton = no
scroll = no
singleinstance = no
showintaskbar = no
contextmenu = no
selection = yes
/>
<style type='text/css'>
.fixed { font-family:courier new, monospace }
</style>
</head>
<script language="VBScript">
CmdLine = oHTA.commandLine
Params = Split(CmdLine,"|")
strBoxTitle = Params( 1 )
strLocalUser = Params( 2 )
Sub window_OnLoad
Document.Title = strBoxTitle
Window.ResizeTo 400, 200 + 70
Window.MoveTo Window.screen.width / 2 - 200, Window.screen.height / 2 - 200
End Sub
Function SubmitBtn()
Window.Close
End Function
</script>
<body bgcolor=Silver>
<center><form>
<b>strBoxTitle</b><p>
<table>
<tr><td colspan=2 align=left>
Please enter your username and password:<br><br>
</td></tr><tr><td valign=top>
Username:
</td><td>
<input id='userid' size=20 class='fixed' value=strLocalUser>
</td></tr><tr><td valign=top>
Password:
</td><td>
<input type='password' id='passwd' size=20 class='fixed'><p>
</td></tr>
</table>
<p>
<input type='button' value='Submit' id='but0' onclick='SubmitBtn()'>
</form></center>
</body>
</html>
正确地显示了带有两个输入字段的输入框。不幸的是,就我而言。我的两个问题是:
- 如何获取输入框来显示strboxtitle和strlocaluser变量的值,而不是文本“ strboxtitle”和“ strlocaluser”?
- 如何将用户输入的值从UserID和密码传递给呼叫VBScript?
事先感谢您的所有指导和建议。
UPDATE: I figured out the answer to my first question. I used two methods, actually. For the "strBoxTitle" variable, I replaced the line:
<b>strBoxTitle</b><p>
with this
<b>
<script>document.write( strBoxTitle )</script>
</b><p>
which correctly displayed the variable's value, rather than its name. This didn’t work for the "strLocalUser" variable, however, because it was inside an input tag. For that one, I added the line
document.getElementById("userid").value = strLocalUser
to my window_OnLoad function, and changed the input tag from
<input id='userid' size=20 class='fixed' value=strLocalUser>
to just
<input id='userid' size=20 class='fixed'>
That also worked, filling in the user input field with the value of "strLocalUser", not to mention preventing me from needing to nest a script tag inside the input tag, which apparently is not allowed.
ORIGINAL QUESTION:
I'm trying to write an HTA file that gets called from a Vbscript file to get user input. The HTA file is called with the command
objWShell.Run ".\UserInput.hta | " & "Please Enter Your Credentials" & _
" | " & strLoginID,1,True
The HTA file "UserInput.hta", which I wrote following examples here in Stack Overflow, is
<!DOCTYPE html>
<html>
<head>
<hta:application
id = oHTA
border = dialog
innerborder = no
caption = yes
sysmenu = no
maximizebutton = no
minimizebutton = no
scroll = no
singleinstance = no
showintaskbar = no
contextmenu = no
selection = yes
/>
<style type='text/css'>
.fixed { font-family:courier new, monospace }
</style>
</head>
<script language="VBScript">
CmdLine = oHTA.commandLine
Params = Split(CmdLine,"|")
strBoxTitle = Params( 1 )
strLocalUser = Params( 2 )
Sub window_OnLoad
Document.Title = strBoxTitle
Window.ResizeTo 400, 200 + 70
Window.MoveTo Window.screen.width / 2 - 200, Window.screen.height / 2 - 200
End Sub
Function SubmitBtn()
Window.Close
End Function
</script>
<body bgcolor=Silver>
<center><form>
<b>strBoxTitle</b><p>
<table>
<tr><td colspan=2 align=left>
Please enter your username and password:<br><br>
</td></tr><tr><td valign=top>
Username:
</td><td>
<input id='userid' size=20 class='fixed' value=strLocalUser>
</td></tr><tr><td valign=top>
Password:
</td><td>
<input type='password' id='passwd' size=20 class='fixed'><p>
</td></tr>
</table>
<p>
<input type='button' value='Submit' id='but0' onclick='SubmitBtn()'>
</form></center>
</body>
</html>
That correctly displays an input box with two input fields. Unfortunately, that's as far as I've gotten. My two questions are:
- How do I get the input box to display the values of the strBoxTitle and strLocalUser variables, instead of the text "strBoxTitle" and "strLocalUser"?
- How do I pass the user-entered values from the input boxes userid and password back to the calling Vbscript?
Thanks in advance for all guidance and suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您修改的脚本以通过注册表传递结果:
userInput.hta
testuserInput.vbs
其他更改:1)添加了
meta
line将文档模式设置为ie = 9(仅使用!doctype
设置HTA通常在IE = 7模式中),2)添加Center -Window
cance totexbar的功能使用availwidth
和availheight
,3)将重点放在密码字段上,以便用户可以立即开始键入,4)添加了of
Enter 因此,用户不必使用鼠标,5)消除了在这种情况下不必要的
form
标签,并干扰了直接通过ID引用元素的能力,例如passwd.value ,6)用
用户ID
通过领先空间传递的问题,7)使用span
标题文本(只是显示另一种方法)。其他建议:删除冗余请求。按照书面形式,该接口具有
,请输入您的凭据
,然后请输入您的凭据,然后,请输入您的用户名和密码
。Here's your script modified to pass the result back via the registry:
UserInput.hta
TestUserInput.vbs
Other changes: 1) Added a
meta
line to set the document mode to IE=9 (with only!DOCTYPE
set the HTA will usually be in IE=7 mode), 2) Added aCenterWindow
function that accounts for taskbar usingavailWidth
andavailHeight
, 3) Set focus on the password field so the user can immediately start typing, 4) Added a check for press ofEnter
so user doesn't have to use mouse, 5) Eliminated theform
tag which is unnecessary in this context and interferes with ability to reference elements directly by id such aspasswd.value
, 6) fixed issue withuserid
being passed with a leading space, 7) used aspan
for the title text (just to show another way to do it).Other suggestion: Remove redundant requests. As written, the interface has
Please Enter Your Credentials
, followed byPlease Enter Your Credentials
, followed byPlease enter your username and password
.