html - 文件打开时 HTA 出错

标签 html vbscript hta

我正在使用 Rob van der Woude 的脚本来打开文件对话框(来自 here 的顶部帖子),该脚本显然应该在 HTA 中工作,但我收到一条错误消息:

"ActiveX component can't create object: 'UserAccounts.CommonDialog'"

最佳答案

这个功能可能对你有帮助!

BrowseForFile.vbs

   '************************************************************************************** 
    ' GetFileDlg() And GetFileDlgBar() by omen999 - may 2014 - http://omen999.developpez.com
    ' Universal Browse for files function  
    ' compatibility : all versions windows and IE - supports start folder, filters and title
    ' note : the global size of the parameters cannot exceed 191 chars for GetFileDlg and 227 chars for GetFileDlgBar
    '**************************************************************************************
    Function GetFileDlg(sIniDir,sFilter,sTitle)
     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
    End Function

    Function GetFileDlgBar(sIniDir,sFilter,sTitle)
     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
    End Function

    ' sample test
    sIniDir = "C:\Windows\Fonts\*"
    sFilter = "All files (*.*)|*.*|Microsoft Word (*.doc;*.docx)|*.doc;*.docx|Adobe pdf (*.pdf)|*.pdf|"
    sTitle = "GetFileDlg by omen999 2014 - omen999.developpez.com"

    ' (sIniDir + sFilter + sTitle) size doesn't exceed 191 chars (227 for GetFileDlgBar)
    ' MsgBox Len(Replace(sIniDir,"\","\\")) + Len(sFilter) + Len(sTitle)

    ' sIniDir must be conformed to the javascript syntax
    rep = GetFileDlg(Replace(sIniDir,"\","\\"),sFilter,sTitle)
    MsgBox rep & vbcrlf & Len(rep)

关于html - 文件打开时 HTA 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31770606/

相关文章:

batch-file - 如何将退出状态从 HTA (vbscript) 返回到调用批处理文件

html - 后台线程中来自 HTML 的 NSAttributedString

html - 如何在出现在模态之外的 Bootstrap 模态中修复 PDF

jquery - 在 bootstrap4 中平滑滑动列

csv - 使用经典的 asp (vbscript) 从 csv 字符串中删除不需要的 chr(13)

javascript - Chrome 中 ActiveXobject 的任何替代功能?

使用参数调用 VBA 例程的 JavaScript

javascript - 如何将图像(以 HTML Canvas 中的数据 URL 形式给出)上传到 facebook?

vba - Excel VBA - 宏错误 - 宏可能不可用 - 自动刷新

ruby - 当通过 OLE 从 Ruby 或 VBS 调用时,Word Document.SaveAs 忽略编码