Advertisement
mlhaufe

VBScript File Browser, IE7+

Jun 14th, 2011
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Bypasses c:\fakepath\file.txt problem
  2. Function BrowseForFile()
  3.     Dim shell : Set shell = CreateObject("WScript.Shell")
  4.     Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  5.     Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
  6.     Dim tempName : tempName = fso.GetTempName()
  7.     Dim tempFile : Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")
  8.     tempFile.Write _
  9.         "<html>" & _
  10.         "    <head>" & _
  11.         "        <title>Browse</title>" & _
  12.         "    </head>" & _
  13.         "    <body>" & _
  14.         "        <input type='file' id='f'>" & _
  15.         "        <script type='text/javascript'>" & _
  16.         "            var f = document.getElementById('f');" & _
  17.         "            f.click();" & _
  18.         "            var shell = new ActiveXObject('WScript.Shell');" & _
  19.         "            shell.RegWrite('HKEY_CURRENT_USER\\Volatile Environment\\MsgResp', f.value);" & _
  20.         "            window.close();" & _
  21.         "        </script>" & _
  22.         "    </body>" & _
  23.         "</html>"
  24.     tempFile.Close
  25.  
  26.     shell.Run tempFolder & "\" & tempName & ".hta", 1, True
  27.  
  28.     BrowseForFile = shell.RegRead("HKEY_CURRENT_USER\Volatile Environment\MsgResp")
  29.     shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp"
  30. End Function
  31.  
  32. MsgBox BrowseForFile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement