[英]How do open an HTML file with a default application using VBScript?
I have an HTML file C:\\Program Files\\my_html_files\\file.html
. 我有一个HTML文件
C:\\Program Files\\my_html_files\\file.html
。 How do I open this file using VBScript? 如何使用VBScript打开此文件? (By "open" I mean open it with the default application, as if it was double-clicked in Explorer.)
(通过“打开”我的意思是使用默认应用程序打开它,就好像它在资源管理器中双击一样。)
The following VBScript code does the equivalent of double clicking on the file.html and having the default open command occur for that file: 以下VBScript代码相当于双击file.html并对该文件进行了默认的open命令:
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run """C:\Program Files\my_html_files\file.html"""
If you want to get really tricksy you can omit the variable declaration and write it in one line of code: 如果你想变得非常狡猾,你可以省略变量声明并将其写在一行代码中:
CreateObject("WScript.Shell").Run """C:\Program Files\my_html_files\file.html"""
NB Strings may require to be enquoted to handle paths containing spaces. NB字符串可能需要被引用来处理包含空格的路径。 This can be done using the
Chr(34)
suggestion by @aland or as I've done in my code examples. 这可以使用@aland的
Chr(34)
建议或者在我的代码示例中完成。
Do you mean open the file in Internet Explorer? 你的意思是在Internet Explorer中打开文件?
Dim objIE
'' Create an IE object
Set objIE = CreateObject("InternetExplorer.Application")
'' Open file
objIE.Navigate "C:\Program Files\my_html_files\file.html"
你可以用它
CreateObject("WScript.Shell").Run Chr(34) & "C:\\Program Files\\my_html_files\\file.html" & Chr(34)
You can use the File System Object like this: 您可以像这样使用文件系统对象 :
Set FSO=CreateObject("Scripting.FileSystemObject")
Set iFile = FSO.OpenTextFile ("C:\Program Files\my_html_files\file.html")
Data = iFile.ReadAll
MsgBox(Data)
iFile.Close
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.