0

How do I insert double-quotes in a string if I am using VBScript in the Windows Scripting Host environment?

Suppose I want to execute this line:

notepad.exe "C:\Some Folder\foo.txt"

How do I write this line? I tried it both ways but it gives me an expected identifier error.

WshShell.Run("%windir%\notepad.exe \"C:\Some Folder\foo.txt\"")

WshShell.Run("%windir%\notepad.exe ""C:\Some Folder\foo.txt""")
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
  • Are you actually using a hard-coded path, or is the path coming from a variable? I took the second line exactly and just tried running it and it launched Notepad and tried to load "C:\Some Folder\foo.txt". I didn't get "expected identifier". – Cheran Shunmugavel Feb 09 '14 at 19:07

1 Answers1

0

Try this

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "notepad.exe C:\Users\pankaj.jaju\Desktop\TO DO.txt"
Set oShell = Nothing

a. You dont need to put double quotes. In my example, I have used a file with space in its name and it works fine

b. You dont really need to use "%windir%\notepad.exe unless your notepad is installed in unusual location.

Hope this helps.

Pankaj Jaju
  • 5,371
  • 2
  • 25
  • 41