0
votes

Im trying to browse to files.

It works fine as a simple vbs but when inside a HTA produces an Error.

Like this:

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.

I could call a separate vbs and write to file then get it that way.

1
<html> <head> <title>HTA Test</title> <HTA:APPLICATION ID="objTest" APPLICATIONNAME="HTATest" SCROLL="no" SINGLEINSTANCE="yes" > </head> <SCRIPT LANGUAGE="VBScript"> Path = BrowseToFile msgbox "Path = " & Path 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 </SCRIPT> <body> </body>CJR
Please do not post code snippets in comments as it becomes slightly unreadable. Update your question instead, please.JosefZ

1 Answers

0
votes

Wrong escaped nested double quotes: instead of

... new ActiveXObject(""Scripting.FileSystemObject"")... 

use single quotation marks as follows:

... new ActiveXObject('Scripting.FileSystemObject')... 

Edit: in your HTATest.hta I see some weird for me approach:

  • nested <script> ... <script> ... </script> ... </script>
  • launched mshta.exe from HTATest.hta i.e., as a matter of fact, from mshta.exe HTATest.hta

Next hta works(?):

<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>

Note <//script> instead of </script> within BrowseToFile() function. However, this workaround I don't regard as a solution...


Here's a simple hta example: does the same as yours one but without troubles

<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>