0

I'm using Rasdial.exe to create a new dial-up connection, Its displays the errors in console mode. Is there a way to make the errors appear on GUI? How does windows displays the error codes as user interface?

Update:

I used "Rasphone.exe" which does what I expected. i.e It shows the error messages in user interface and not in command prompt. But is this the correct way to use "RASPhone.exe" instead of "RASDial.exe"?

2vision2
  • 4,933
  • 16
  • 83
  • 164
  • To make sure, are you asking how to spawn a child process, capture its standard output, and echo it to a GUI? – Ed Bayiates Jul 09 '12 at 15:10
  • 1
    Probably by using the rich underlying API; http://msdn.microsoft.com/en-us/library/aa377827(v=vs.85).aspx – Alex K. Jul 09 '12 at 15:11
  • 1
    You might make your life easier by using DotRas: http://dotras.codeplex.com/ – roken Jul 09 '12 at 15:15
  • @AresAvatar yes you r rit! It would be better if I get the actual error messages which I get when I make a connection manually. – 2vision2 Jul 09 '12 at 15:48
  • @user1317084: See http://stackoverflow.com/questions/285760/how-to-spawn-a-process-and-capture-its-stdout-in-net for details on how to do this. – Ed Bayiates Jul 10 '12 at 17:23

1 Answers1

3

If you're really wanting to control what happens with the user interface while dialing a connection I would suggest you take a look at the DotRas SDK found on CodePlex.

using DotRas;

RasHandle handle = null;
using (RasDialer dialer = new RasDialer())
{
    dialer.StateChanged += (sender, e) => 
       {
           // Update your user interface.
       };
    dialer.EntryName = "Your Entry Here";
    dialer.PhoneBookPath = @"C:\YourPhoneBook.pbk";
    dialer.Credentials = new NetworkCredential("Some", "User");

    handle = dialer.DialAsync();
}

This would give you the ability to update your user interface however you want whenever the state of the connection changes without having to route the updates made to the console application to your user interface.

Here's a link: http://dotras.codeplex.com

Jeff Winn
  • 804
  • 8
  • 14
  • Won't the `using` block instantly `Dispose()` the `RasDialer` right after the `DialAsync()` call in this example? Unless the `RasDialer` is very strangely implemented, that should leave it in a disposed state where it won't ever call the `StateChanged` event. – Alex Mar 05 '15 at 11:43