2

I am receiving a error when running a WScript.Shell Run with a path that has a spaces in it.

I've tried several different variations that result in the same error.

CreateObject("WScript.Shell").Run """Program Files\scripts\exe\PsExec64.exe -accepteula -realtime -d c:\windows\system32\RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 264"" ", 0, True
CreateObject("WScript.Shell").Run "Program Files\scripts\exe\PsExec64.exe -accepteula -realtime -d c:\windows\system32\RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 264", 0, True
CreateObject("WScript.Shell").Run "'Program Files\scripts\exe\PsExec64.exe -accepteula -realtime -d c:\windows\system32\RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 264'", 0, True
CreateObject("WScript.Shell").Run("Program Files\scripts\exe\PsExec64.exe -accepteula -realtime -d c:\windows\system32\RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 264", 0, True)

I understand the space in the path is causing an error, I just cant wrap my head around wrapping with quotes correctly.

AHeyne
  • 3,377
  • 2
  • 11
  • 16
  • 2
    You're calling a relative path (starting with `Program Files\scripts\...`. Try to fully qualify the path by prefixing `C:\ ` (if this is your drive). Also you would have to use this syntax `"""Program Files\scripts\exe\PsExec64.exe"" -accepteula -realtime -d c:\windows\system32\RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 264", 0, True"` – AHeyne Oct 19 '19 at 09:13
  • 2
    The last `"` in my comment has to be removed. Unfortunately I cant remove it any more. – AHeyne Oct 19 '19 at 09:19
  • UGH :| You're a God, thank you. I've been looking at this for hours and you fixed it in minutes. I always feel dumb posting here because it's usually something so stupid. –  Oct 19 '19 at 09:35
  • 1
    Working with quotes is always tricky. In almost all my vbscripts I include a function to double-quote variables. As long as you propertly identify them, it can be of help. `Function dq(ByVal s) dg = Chr(34) & s & Chr(34) End Function` (Code in comments looks rubbish, sorry) – Rno Oct 19 '19 at 23:16

1 Answers1

0

you need to specify the drive letter, e.g. c:\program files

Rosski
  • 62
  • 4