"通过vbscript打开"选项

Ram*_*esh 3 vbscript

手动我们右键单击文件并选择"打开方式"选项以其他格式打开.

现在我需要通过vbscript来做到这一点

Hel*_*len 7

要使用特定应用程序打开文件,请使用WshShell.Runmethood运行该应用程序并将文件名作为参数传递.

这是一个在记事本,Internet Explorer和Microsoft Word中打开相同文本文件的示例:

strFileName = "c:\myfile.txt"
Set oShell = CreateObject("WScript.Shell")

oShell.Run "notepad "  & strFileName
oShell.Run "iexplore " & strFileName
oShell.Run "winword "  & strFileName
Run Code Online (Sandbox Code Playgroud)

请注意,如果文件名包含空格,则需要将其括在引号中,如下所示:

oShell.Run "winword ""c:\my file.txt"""
Run Code Online (Sandbox Code Playgroud)