Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to determine the process id of a visual studio application

Posted on 2011-02-27
2
Medium Priority
?
422 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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Loops Section Overview

972 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