Passing arguments to a DOS command Visual Basic 2010

I would like to be able to pass arguments received from text boxes into a command line. What I'm trying to do is use the "rasdial" command and pass the username and password into it. Currently I can do this using a batch file however I find that this may be a little less secure than should be. Whereas if I have the user put in his username and password when he goes to login it would add a level of security.

So far I have come up with the code listed below and it does seem to work for other "commands". For this one I am getting an error message "Remote Access error 623 - The system could not find the phone book entry for this connection"

Does any one have any ideas on what I am missing here?  As I said I can call a batch file and it runs perfectly. If I were using a DOS command line it would be "RASDIAL "MYVPN" username password".  I am suspecting that this all has something to do with the quotation marks around VPN.


Thank you for any help you are able to send my way
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myProcess As New Process()
        myProcess.StartInfo.UseShellExecute = False
        myProcess.StartInfo.RedirectStandardOutput = True
        Try
            myProcess.StartInfo.FileName = "Rasdial"
            myProcess.StartInfo.Arguments = "VPN"
            myProcess.StartInfo.Arguments = TextBox2.Text   ' type "User" in the Text Box
            myProcess.StartInfo.Arguments = TextBox3.Text   'pasword
            myProcess.StartInfo.CreateNoWindow = True
            myProcess.Start()
            TextBox1.Text = _
               Replace(myProcess.StandardOutput.ReadToEnd(), _
               Chr(13) & Chr(13), Chr(13))
            myProcess.WaitForExit()
        Catch ex As Win32Exception
            MsgBox((ex.Message + ". Error Detected."))
        End Try

Open in new window

Pat ClancyCEOAsked:
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.

Fernando SotoRetiredCommented:
Hi Pat;

The property Process.StartInfo.Arguments is of type string so doing the following will over write the previous assignments to the property.

myProcess.StartInfo.Arguments = "VPN"
myProcess.StartInfo.Arguments = TextBox2.Text   ' type "User" in the Text Box
myProcess.StartInfo.Arguments = TextBox3.Text   'pasword

Open in new window

So try replacing the above three lines with the following.
myProcess.StartInfo.Arguments = "VPN " & TextBox2.Text.Trim() & " " & TextBox3.Text() 

Open in new window

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
Pat ClancyCEOAuthor Commented:
The solution is absolutely correct and my kudos for the very quick response. Awesome, I've been fighting with this for several hours not even thinking that one argument was overriding the other. Great solution, great timing
Fernando SotoRetiredCommented:
Happy that worked out for you, glad I was able to help.
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.