'Open File' dialog by VBS

来源:互联网 发布:360度全景软件 编辑:程序博客网 时间:2024/06/04 20:02

Function BrowseForFile()    Dim shell : Set shell = CreateObject("WScript.Shell")    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")    Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)    Dim tempName : tempName = fso.GetTempName()    Dim tempFile : Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")    tempFile.Write _    "<html>" & _    "<head>" & _    "<title>Browse</title>" & _    "</head>" & _    "<body>" & _    "<input type='file' id='f' />" & _    "<script type='text/javascript'>" & _    "var f = document.getElementById('f');" & _    "f.click();" & _    "var shell = new ActiveXObject('WScript.Shell');" & _    "shell.RegWrite('HKEY_CURRENT_USER\\Volatile Environment\\MsgResp', f.value);" & _    "window.close();" & _    "</script>" & _    "</body>" & _    "</html>"    tempFile.Close    shell.Run tempFolder & "\" & tempName & ".hta", 0, True    BrowseForFile = shell.RegRead("HKEY_CURRENT_USER\Volatile Environment\MsgResp")    shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp"End Function'Author: Demon'Website: http://demon.tw'Date: 2011/6/2path = BrowseForFile()If path <> "" Then WScript.Echo path

Refer to: http://demon.tw/programming/vbs-open-file-dialog.html




原创粉丝点击