Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quotes or no quotes while shelling?

Status
Not open for further replies.

JFoushee

Programmer
Oct 23, 2000
200
US
Is there some OS option that determines use/non-use of quotes when shelling out?

I have a job class that includes two parameters Shell_Command (the path of .exe) and Shell_Parameters...

Code:
Public Class clsJob

    Public Sub sub_Run_Job_Now()

        Dim strCommand As String = RTrim("""" & Me.Shell_Command & """ " & Me.Shell_Parameters)

        Try
            sub_Kick_Off_Job(strCommand)
        Catch ex As Exception
            Throw New Exception("Command `" & strCommand & "` returned '" & ex.Message & "'")
        End Try

        ' add history information...

    End Sub

    Private Sub sub_Kick_Off_Job(ByVal strCommand As String)

        Try
            Shell(strCommand, AppWinStyle.NormalFocus, False, 5000)
        Catch ex As Exception
            Throw New Exception(Err.Description)
        End Try

    End Sub

End Class

On my machine, the following scenario works:
Shell_Command = C:\Windows\system32\rundll32.exe
Shell_Parameters = user32.dll,LockWorkStation

but not this:
Shell_Command = "C:\Windows\system32\rundll32.exe" (with quotes)
Shell_Parameters = user32.dll,LockWorkStation
(Error: Command `""C:\Windows\system32\rundll32.exe"" user32.dll,LockWorkStation` returned 'File not found.')

On another machine, the opposite is true.

What might cause this behavior?
(Unfortunately, VB.NET is not available on the other machine to debug.)
 
Search this forum for System.Diagnostic.Process.

Seems to work better.

I hope this helps.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top