vbscriptwordpad

VBscript - "The system cannot find the file specified"


I'm trying to write a short VBScript, which opens "calc.exe" and "wordpad.exe". Well the problem is that VBScript won't let me open "wordpad.exe". I've tried to run the script as an admin, but this doesn't helped.

My Script looks like this:

Set WshShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "C:\Program Files\Windows NT\Accessories\wordpad.exe"
WSHShell.Run "C:\Windows\System32\calc.exe"
x=msgbox("Test",4096,Test) 

I've also tried to define the path like this:

WSHShell.Run ""C:\Program Files\Windows NT\Accessories\wordpad.exe""

Also not working. I'm getting the message "Expected end of statement"

Is there a solution to open "wordpad.exe" by its path?

Kind regards


Solution

  • The shell uses blanks/spaces as separators. So paths containing blanks/spaces need to be quoted. The way to quote " in VBScript string literals is to double them. So:

    WSHShell.Run "C:\Program Files\Windows NT\Accessories\wordpad.exe"
    ==>
    WSHShell.Run """C:\Program Files\Windows NT\Accessories\wordpad.exe"""