I have the following code in a VBS file; it displays a file open dialog box
and returns the full path to the file chosen. The program should then open
the selected file, but I get an error that the file was not found; how can it
not be found if I just picked it?
The error occurs on the last line, char 1:

Set oDialog = CreateObject("UserAccounts.CommonDialog")
oDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
oDialog.FilterIndex = 2
iResult = oDialog.ShowOpen
If iResult = 0 Then
Wscript.Quit
Else
sTarget = oDialog.FileName
'Wscript.Echo sTarget
End If
Set oWSHShell = CreateObject("WScript.Shell")
oWSHShell.Run sTarget, 3, True

Re: Help debug File Not Found by Ayush

Ayush
Wed Apr 04 13:13:55 CDT 2007

[XP]s message :
> I have the following code in a VBS file; it displays a file open dialog box
> and returns the full path to the file chosen. The program should then open
> the selected file, but I get an error that the file was not found; how can it
> not be found if I just picked it?
> The error occurs on the last line, char 1:

> Set oDialog = CreateObject("UserAccounts.CommonDialog")
> oDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
> oDialog.FilterIndex = 2
> iResult = oDialog.ShowOpen
> If iResult = 0 Then
> Wscript.Quit
> Else
> sTarget = oDialog.FileName
> 'Wscript.Echo sTarget
> End If
> Set oWSHShell = CreateObject("WScript.Shell")
> oWSHShell.Run sTarget, 3, True

Try
oWSHShell.Run """"& sTarget &"""", 3, True


Good Luck, Ayush.
--
Script Center-Script Repository : http://snipurl.com/Script_Repository