Link to home
Start Free TrialLog in
Avatar of Pat Clancy
Pat ClancyFlag for Canada

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
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
Avatar of Pat Clancy

ASKER

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
Happy that worked out for you, glad I was able to help.