itnifl
asked on
Run batch file with arguments from Visual basic .Net
I am trying to run a batch fine from Visual basic .Net. I have tried this:
Dim runString As String = ControlChars.Quote & Application.StartupPath & "\myBat.bat" & ControlChars.Quote
System.Diagnostics.Process .Start(run String & " " & ControlChars.Quote & lstServersBox.GetItemText( lstServers Box.Items( intServerC ounter)) & ControlChars.Quote & " " & ControlChars.Quote & txtUsername.Text & ControlChars.Quote & " " & ControlChars.Quote & txtPassword.Text & ControlChars.Quote & " " & ControlChars.Quote & sPath & ControlChars.Quote)
Also this:
Dim runString As String = ControlChars.Quote & Application.StartupPath & "\myBat.bat" & ControlChars.Quote
Shell("cmd /c " & runString & " " & """" & lstServersBox.GetItemText( lstServers Box.Items( intServerC ounter)) & """" & " " & """" & txtUsername.Text & """" & " " & """" & txtPassword.Text & """" & " " & """" & sPath & """", AppWinStyle.Hide)
In the first example it seems to try to execute the whole thing as one path and not one path with arguments. In the second example, no matter how I tru to quote the string, it doesn't find the path if there is a space in it, or if there is none, tries to execute the whole thing as if it was one path and not a path+filename+arguments.
Any tips?
Dim runString As String = ControlChars.Quote & Application.StartupPath & "\myBat.bat" & ControlChars.Quote
System.Diagnostics.Process
Also this:
Dim runString As String = ControlChars.Quote & Application.StartupPath & "\myBat.bat" & ControlChars.Quote
Shell("cmd /c " & runString & " " & """" & lstServersBox.GetItemText(
In the first example it seems to try to execute the whole thing as one path and not one path with arguments. In the second example, no matter how I tru to quote the string, it doesn't find the path if there is a space in it, or if there is none, tries to execute the whole thing as if it was one path and not a path+filename+arguments.
Any tips?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.