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?
LVL 2
itniflAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
For the .NET version, you send the parameter string as the second parameter to Process.Start()--not concatenated to the program name.

Try this (it should be easier to read):
Dim runString As String = String.Format("""{0}\{1}""", Application.StartupPath, "myBat.bat")
Dim parameters As String = String.Format("""{0}"" ""{1}"" ""{2}"" ""{3}""", lstServersBox.GetItemText(lstServersBox.Items(intServerCounter)), txtUsername.Text, txtPassword.Text, sPath)

System.Diagnostics.Process.Start(runString, parameters)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.