4

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

Homo Sapiens
  • 45
  • 1
  • 1
  • 3
  • Is there a specific reason you're using VBScript/WSH? It's only being kept around now for legacy support; PowerShell is the way of the future. – alroc Oct 28 '15 at 11:22
  • @alroc I'm here using vbs (or bat) and not Powershell because I need users to be able to run my script on their machines - Powershell doesn't do it.... it doesn't run on double-click and even then needs policy settings fixed up before it works. Can't use it – PandaWood Sep 27 '21 at 04:55

1 Answers1

11

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"""
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96