Harsh585762

I am developing a windows application.
In my current project I want to call an exe of another project.
I added .exe and vshost.exe of that project in the bin (in that debug folder) folder of current project.
And on button click i have written following code -
Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process

startInfo = New System.Diagnostics.ProcessStartInfo(gsAppPath & "AddressBook.exe")

pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()

But after this I got error -
AddressBook has encountered a problem and needs to close. We are sorry for the inconvenience.

So how to call that exe.



Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Westor

The way you are starting the exe is correct and it should work, i would try removing pStart.WaitForExit().




Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Harsh

Yes, I tried that but still its not working.





Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Rong-Chun Zhang - MSFT

Hi Harsh,

Just like Westor have said. The way you used are right. I suggest you make these checkings.

  • Make sure, the AddressBook.exe runs correctly when double click on it.
  • Check the parameter of the ProcessStartInfo method. Is it the right path of the AddressBook.exe.

Hope this helps.

Regards






Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Harsh

Ok I got it working using only

pStartAddr.StartInfo = startInfoAddr
pStartAddr.Start()

But now i have one more problem due to this. Now I want to close this child process when I exit from parent process.
I mean when close the application from which I am calling this new exe then that exe should also be closed.
For that I tried - pStartAddr.Close() and pStartAddr.Dispose()
But that new exe doesn't get closed.
So how close that process.





Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Rong-Chun Zhang - MSFT

Hi Harsh ,

Try use the Process.CloseMainWindow Method. e.g.

Code Snippet

namespace MDIForm

{

public partial class ChildFrm2 : Form

{

public ChildFrm2()

{

InitializeComponent();

}

System.Diagnostics.Process mm;

private void ChildFrm2_Load(object sender, EventArgs e)

{

Invalidate();

this.WindowState = FormWindowState.Maximized;

}

private void button1_Click(object sender, EventArgs e)

{

mm = new System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(@"C:\Documents and Settings\v-rzhang\Desktop\Debug\files.exe");

mm.StartInfo = info;

mm.Start();

}

private void ChildFrm2_FormClosed(object sender, FormClosedEventArgs e)

{

if(mm != null)

mm.CloseMainWindow();

}

}

}

Hope this helps.

Regards






Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

timvw

Since you're talking about copying it's vhost.exe i presume it's a .net assembly too.. In that case you could also create an AppDomain and Execute the assembly....

Code Snippet

AppDomain ad = AppDomain.CreateDomain("domain for exe");
ad.ExecuteAssembly("MyApp.exe");






Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Harsh

But before using process.CloseMainWindow that process should be compulsorily running. Otherwise it throws an exception.

In case case that might be running and might not be running. So only if that another exe is running then only it should be closed.





Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Rong-Chun Zhang - MSFT

Hi Harsh,

I am sorry, I forgot this line.

Code Snippet

private void ChildFrm2_FormClosed(object sender, FormClosedEventArgs e)

{

if (mm != null && !mm.HasExited)

mm.Kill();

//mm.CloseMainWindow();

}

Hope this helps.

Regards






Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Rong-Chun Zhang - MSFT

Hi Harsh,

Here is the VB code.

Code Snippet

Public Class Form2

Private mm As System.Diagnostics.Process

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

mm = New System.Diagnostics.Process()

Dim info As New System.Diagnostics.ProcessStartInfo("C:\Documents and Settings\v-rzhang\Desktop\Debug\files.exe")

mm.StartInfo = info

mm.Start()

End Sub

Private Sub ChildFrm2_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles MyBase.FormClosed

If mm IsNot Nothing AndAlso Not mm.HasExited Then

mm.Kill()

'mm.CloseMainWindow()

End If

End Sub

End Class

Hope this helps.

Regards






Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Harsh

I used following code -

If pStartAddr IsNot Nothing AndAlso Not pStartAddr.HasExited Then

pStartAddr.Kill()

End If

but its giving error that - No process is associated with this object (This error is on if condition)





Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Rong-Chun Zhang - MSFT

Hi Harsh,

I didn't get this error under these situation

  • Open this project, do not do anything and close the project;
  • Open this project, click on the button and close the project;
  • Open this project, click on the button , close the new project and then close the project.

Could you provide me some details By the way I am using Visual Studio 2005 in Windows Server 2003 Servide Pack 2.

Hope this helps.

Regards






Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

slash_canadian

Owh, Thank you for your information. I've got it !!




Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

Paul Selormey

Please you MSFT guys should help maintain the aims of this forum. Are you answering Windows Forms Designer questions

Best regards,

Paul.





Re: Windows Forms Designer How to call exe of another project in VB.Net 2005?

the new kid on the block