Solved

How to determine the process id of a visual studio application

Posted on 2011-02-27
2
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34991978
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
ID: 35006945
Thank you.  Sorry for the slow reply.

That's exactly what I needed.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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