[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转贴] VBS 文件选择对话框(无临时文件)

本帖最后由 yu2n 于 2015-11-5 01:05 编辑

VBS 文件选择对话框(无临时文件)
Win7x64 测试通过
  1. '0.vbs
  2. 'How can I filter file type extensions using CreateObject("Scripting.FileSystemObject")?
  3. 'http://www.visualbasicscript.com/How-can-I-filter-file-type-extensions-using-CreateObjectquotScriptingFileSystemObjectquot-m105786.aspx
  4. '初始目录、文件过滤、标题
  5. StrIniDir = ""
  6. StrFilter = "Msi Files (*.msi)|*.msi|All files (*.*)|*.*|Microsoft Word (*.doc;*.docx)|*.doc;*.docx|Adobe pdf (*.pdf)|*.pdf|"
  7. StrTitle = "Select MSI file"
  8. Msgbox GetFileDlg(Replace(StrIniDir,"\","\\"),StrFilter,StrTitle)
  9. Msgbox GetFileDlgBar(Replace(StrIniDir,"\","\\"),StrFilter,StrTitle)
  10. '不在任务栏显示选择框
  11. Function GetFileDlg(sIniDir,sFilter,sTitle)
  12. On Error Resume Next
  13. GetFileDlg=CreateObject("WScript.Shell").Exec("mshta.exe ""about:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg('" & sIniDir & "',null,'" & sFilter & "','" & sTitle & "')));close();}</script><hta:application showintaskbar=no />""").StdOut.ReadAll
  14. End Function
  15. '在任务栏显示选择框
  16. Function GetFileDlgBar(sIniDir,sFilter,sTitle)
  17. On Error Resume Next
  18. GetFileDlgBar=CreateObject("WScript.Shell").Exec("mshta.exe ""about:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg('" & sIniDir & "',null,'" & sFilter & "','" & sTitle & "')));close();}</script>""").StdOut.ReadAll
  19. End Function
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

同理,以下代码也实现了文件选择框功能(无临时文件),只是没有“文件类型过滤”+“自定义标题”功能:
  1. '获取单个文件选择 By Yu2n
  2. Function BrowseForFileByHtaInput()
  3. Dim wShell, oExec
  4. Set wShell=CreateObject("WScript.Shell")
  5. Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=f>" & _
  6. "<script>moveTo(0,-9999);resizeTo(0,0);f.click();" & _
  7. "new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1)." & _
  8. "WriteLine(f.value);close();</script>""")
  9. BrowseForFileByHtaInput = oExec.StdOut.ReadLine
  10. End Function
  11. Msgbox "Select File: " & vbCrLf & BrowseForFileByHtaInput(), vbSystemModal+vbInformation, WScript.ScriptName
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

也收藏一个,学习学习!

TOP

马克

TOP

收藏

TOP

返回列表