我试图浏览文件。
它作为一个简单的vbs工作正常但在HTA内部产生错误。
像这样:
sUserList = BrowseToFile
msgbox sUserList
Function BrowseToFile
Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject(""Scripting.FileSystemObject"").GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
BrowseToFile = oExec.StdOut.ReadLine
End Function
ERROR:
Line 130: Is the wShell.exec
Char 203:
Unterminated String Constant.
我可以调用单独的vbs并写入文件,然后就这样。
答案 0 :(得分:0)
错误的转义嵌套双引号:而不是
... new ActiveXObject(""Scripting.FileSystemObject"")...
使用单引号如下:
... new ActiveXObject('Scripting.FileSystemObject')...
修改:在HTATest.hta
中,我看到一些奇怪的方法:
<script> ... <script> ... </script> ... </script>
mshta.exe
发起HTATest.hta
,事实上,来自mshta.exe HTATest.hta
下一个hta
正常工作(?):
<html>
<head>
<title>HTA Test
</title>
<HTA:APPLICATION ID="objTest" APPLICATIONNAME="HTATest" SCROLL="no" SINGLEINSTANCE="yes" >
</head>
<SCRIPT LANGUAGE="VBScript">
Path = BrowseToFile
msgboxx= "Path = " & Path
Function BrowseToFile()
Set wShell=CreateObject("WScript.Shell")
mshtapar="about:<input type=file id=FILE>"_
& "<script>FILE.click();"_
& "new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);"_
& "close();"_
& "resizeTo(0,0);"_
& "<//script>"
msgboxy= "param =" & mshtapar
Set oExec=wShell.Exec( "mshta.exe " & """" & mshtapar & """")
End Function
</SCRIPT>
<body>
</body>
在<//script>
函数中注意</script>
而不是BrowseToFile()
。但是,这种解决方法我不认为是一种解决方案......
这是一个简单的hta
示例:与您的相同但没有麻烦
<html>
<head>
<title>HTA Test
</title>
<HTA:APPLICATION ID="objTest" APPLICATIONNAME="HTATest" SCROLL="no" SINGLEINSTANCE="yes" >
</head>
<SCRIPT LANGUAGE="VBScript">
<!--
-->
</SCRIPT>
<body>
<input type="file" id=FILE>
</body>