Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

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(runString & " " & ControlChars.Quote & lstServersBox.GetItemText(lstServersBox.Items(intServerCounter)) & 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(lstServersBox.Items(intServerCounter)) & """" & " " & """" & 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?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial