0
WshShell.Run """C:\Program Files\Target.exe"" -s"

In command above, I want to use a string instead of the path, but it is not working!

Directory = "C:\Program Files\Target.exe"
WshShell.Run """Directory"" -s"

How to do it?

1 Answer 1

1

Using Chr(34) might make things clearer.

Directory = "C:\Program Files\Target.exe"
WshShell.Run Chr(34) & Directory & Chr(34) & " -s"

Otherwise, the syntax you're looking for gets a bit complicated:

WshShell.Run """" & Directory & """ -s"

If you need to use a quote character within a string literal, it must be doubled. And if you need to include a VBScript variable, it should be concatenated (&).

Sign up to request clarification or add additional context in comments.

1 Comment

Arguably the best way of handling this is to wrap it in a quoting function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.