Solved

How to determine the process id of a visual studio application

Posted on 2011-02-27
2
410 Views
Last Modified: 2012-05-11
I use my primary Visual Basic (Visual Studio 2010) application as the UI to kick off other secondary VB applications.

I want to monitor which secondary apps are currently open, and then if a user tries to kick off an app that is already open, then I'll kill the first instance before starting the new one.

The problem is that the process that kicks off the secondary app always shows hasexited=True even though the actual app is still running.  I've tried using "setup.exe," "TestApp," and "TestApp.application."

Any ideas?
Private ProcList As New List(Of Process)(5)
Private Sub kickoff(ByVal sender As System.Object, ByVal e As System.EventArgs)
	'app = "MyApp.application"
	'app = "MyApp"
	app = "setup.exe"
	For Each x In ProcList
		If x.StartInfo.FileName Like MyPath & "\" & app Then
			If Not x.HasExited Then x.Kill()
		End If
	Next
	ProcList.Add(Process.Start(MyPath & "\" & app))
End Sub

Open in new window

0
Comment
Question by:motokent
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Try something like this instead:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Launch("c:\some path\folder\appname.exe")
    End Sub

    Private Sub Launch(ByVal FullPathApp As String)
        For Each P As Process In Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(FullPathApp))
            P.Kill()
        Next
        Process.Start(FullPathApp)
    End Sub

Open in new window

0
 

Author Closing Comment

by:motokent
Comment Utility
Thank you.  Sorry for the slow reply.

That's exactly what I needed.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now