10

How do I open a file with VBScript, as if the user had double clicked the file?

1

3 Answers 3

14
CreateObject("WScript.Shell").Run("""C:\Program Files\my_html_files\file.htm""")

And check the application registered with the .htm extension (probably IExplore.exe), in these registry keys:

HKLM\SOFTWARE\Classes\.htm
HKLM\SOFTWARE\Classes\htmlfile\shell\open\command
HKCU\Software\Classes\.htm
Sign up to request clarification or add additional context in comments.

Comments

3
CreateObject("WScript.Shell").Run("C:\\Program Files\\my_html_files\\file.htm")

4 Comments

file.htm exist but when I run the script I get the message that the system cant find the specific file?
Try to put script file in the same folder as target html file, remove the absolute path and try again
I cant because I must to run it only from this PATH
Backslashes aren't special characters in VBScript, so they don't need to be escaped.
1

http://msdn.microsoft.com/en-us/library/bb774148(VS.85).aspx

<script language="VBScript">
function fnShellExecuteVB()
    dim objShell

    set objShell = CreateObject("Shell.Application")

    objShell.ShellExecute "notepad.exe", "", "", "open", 1

    set objShell = nothing
end function
</script>

3 Comments

can you please give me example how to open the C:\Program Files\my_html_files\file.html file thx
I get the error message: ActiveX component cant create objecte:'shell_application' ?
It should be "Shell.Application", not "shell.Shell_Application".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.