1

I am trying to use WScript.Shell.Run to open a file. The file isn't always the same type and I want to rely on Windows using the default program to open the file.

For .txt with Notepad set it works fantastic. For .htm (or .html) with Internet Explorer 8 or 9 (Windows XP or Windows 7) the command will execute and one of two things will happen.

  1. If no other instances of IE are running before the script starts it will open IE and just hang not displaying anything.
  2. If at least 1 other IE window (or tab) is open the script will execute and perform the default action of opening a new tab or window and display the content of the .htm (or .html) file.

The problem is not apparent in other browsers, like if you change the default handler for .htm to say Chrome it works in both cases as intended always displaying the content.

test.vbs

Set App = Wscript.CreateObject("WScript.Shell")
App.Run("C:\test.htm")
WScript.Quit

test.htm

<html>
<head><title>Test File</title></head>
<body><p>Test File</p></body>
</html>
4

1 に答える 1

2

WScript.Shell.Runを使用する代わりに、次のコードブロックが機能することがわかりました。

Set objShell = CreateObject( "Shell.Application" )
objShell.ShellExecute "C:\Backups\Scripts\test.htm"
于 2012-10-26T21:21:07.297 に答える