VB.net exec command line program

N

Nicholas Then

I am writing an application that will call a command line
application. Basically I have set up the windows 2003
POP3/SMTP service and to change a password of a mailbox,
I need to execute the following program:

winpop changepwd (e-mail address removed) SomePassword

I have the folowing code in a .NET app so that I can
change the password using a GUI:

Try
Dim p As New Process

With p.StartInfo
.UseShellExecute = True
.FileName = "winpop.exe"
.Arguments = "changepwd " &
txtUsername.Text & " " & txtPassword.Text
End With

' Execute the process and wait for it to
exit
If p.Start() Then
p.WaitForExit()
End If
Catch ex As Exception
MsgBox(ex.Message,
MsgBoxStyle.Critical, "System Notification")
End Try

If lets say that a user could not be found, the command
line program will tell me about it as seen here: A
problem occured. The password for this mailbox could not
be changed.
The specified domain either does not exist or could not
be contacted.

Is there a way that I can get these messages to appear in
my VB.net app so that I know when an error occurs? Try
Catch will not grab these.
 
Y

Yves Tourchot

Nicholas Then said:
I am writing an application that will call a command line
application. Basically I have set up the windows 2003
POP3/SMTP service and to change a password of a mailbox,
I need to execute the following program:

winpop changepwd (e-mail address removed) SomePassword

I have the folowing code in a .NET app so that I can
change the password using a GUI:

Try
Dim p As New Process

With p.StartInfo
.UseShellExecute = True
.FileName = "winpop.exe"
.Arguments = "changepwd " &
txtUsername.Text & " " & txtPassword.Text

'redirect the standard ouput to your app

.RedirectStandardOutput=true
End With

' Execute the process and wait for it to
exit
If p.Start() Then
p.WaitForExit()

'now get the result

Dim str as string
str = p.StandardOutput.ReadToEnd();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top