1
votes

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>
1

1 Answers

2
votes

I found the following code block works in place of using WScript.Shell.Run

Set objShell = CreateObject( "Shell.Application" )
objShell.ShellExecute "C:\Backups\Scripts\test.htm"