Solved

How to determine the process id of a visual studio application

Posted on 2011-02-27
2
415 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SqlServer no dupes 25 37
Help with adding DLL file in Windows project 20 40
Very Large data in MYSQL 7 73
VB.Net Determine if a mapped network drive exists 2 30
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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 …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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