VBScript system cannot find the path specified

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
Forgive my newbie-ness with VBScript, hello x10hosting forum.
I am trying to create a script that will open Sound Recorder and Debut at the same time so I can record my Microphone and Speakers in a screen capture.
The code looks great! But it isn't working:
Code:
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep(100)
set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("%windir%/system32/sndrec32.exe") Then
 WshShell.Run "%windir%/system32/sndrec32.exe"
 WScript.Sleep(100)
 WshShell.AppActivate "Sound - Sound Recorder"
 WScript.Sleep(100)
 WshShell.SendKeys " "
 WScript.Sleep(100)
 WshShell.Run "C:\Program Files\NCH Software\Debut\debut.exe"
 do
 WScript.Sleep(60400)
 WshShell.sendkeys " "
 loop
Else
 WshShell.Run "sndrec32.exe"
 WScript.Sleep(100)
 WshShell.AppActivate "Sound - Sound Recorder"
 WScript.Sleep(100)
 WshShell.SendKeys "  "
 WScript.Sleep(100)
 If filesys.FileExists("C:/Program Files (x86)/NCH Software/Debut/debut.exe") Then
  WshShell.Run "C:/Program Files (x86)/NCH Software/Debut/debut.exe"
 ElseIf filesys.FileExists("C:/Program Files/NCH Software/Debut/debut.exe") Then
  WshShell.Run "C:/Program Files/NCH Software/Debut/debut.exe"
 End If
 do
 WScript.Sleep(24171)
 WshShell.sendkeys " "
 loop
End If
It's supposed to do what it looks like it's supposed to do (the sndrec32.exe is in the same folder with the script), but at line 24 it returns "System cannot find the path specified." That is this line right here:
Code:
  WshShell.Run "C:/Program Files (x86)/NCH Software/Debut/debut.exe"
That's strange because one line above it, I check if that file exists, so it must exist in order to execute:
Code:
 If filesys.FileExists("C:/Program Files (x86)/NCH Software/Debut/debut.exe") Then
Well, apparently not. And I suspect that this is a problem with spaces, brackets maybe? But I can't figure out how to fix this. Any ideas what newbie-ish mistake I'm making here?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
The shell sees: C:/Program Files (x86)/NCH Software/Debut/debut.exe

Because of the spaces (thanks Microsoft), it thinks you want to run C:/Program

You need get quotation marks around the whole path. (In a real programming language you would just use "\"C:/Program Files (x86)/NCH Software/Debut/debut.exe\"" ie you need quotes inside of the quotes. Not sure how to do that in vBScript.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Oddly, the quotation mark is its own escape in VBScript, so to get one, you need two. To get a literal string, the whole of which is surrounded by quotatin marks, you need to use three at each end (the first and last as string delimiters), so:

Code:
WshShell.Run """C:/Program Files (x86)/NCH Software/Debut/debut.exe"""

Non-Microsoft variants of VB (particularly LotusScript) offer more than one string delimiter ("string here", {string here}, |string here|) so that you rarely run into a problem where you need to escape your delimiters (a single string literal fragment would need to contain all three of a double quote/second/inch mark, a pipe and an opening curly brace before you run into trouble, and you can always break that up).
 
Last edited:

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
Yup, that was the problem. I even cleaned this script up a little and now it looks like this:
Code:
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep(100)
set filesys = CreateObject("Scripting.FileSystemObject")
WshShell.Run "%windir%/System32/SoundRecorder.exe"
WScript.Sleep(100)
WshShell.AppActivate "Sound Recorder"
WScript.Sleep(100)
WshShell.SendKeys "abc"
WshShell.SendKeys "%s"
WScript.Sleep(100)
If filesys.FileExists("C:/Program Files (x86)/NCH Software/Debut/debut.exe") Then
 WshShell.Run("""C:/Program Files (x86)/NCH Software/Debut/debut.exe""")
ElseIf filesys.FileExists("C:/Program Files/NCH Software/Debut/debut.exe") Then
 WshShell.Run("""C:/Program Files/NCH Software/Debut/debut.exe""")
End If
And it works as expected! You guys are geniuses! :)
 
Top