Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 307
Homo Sapiens Avatar asked Dec 18 '22 22:12

Homo Sapiens


1 Answers

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"""
like image 120
Ekkehard.Horner Avatar answered Feb 23 '23 20:02

Ekkehard.Horner