Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to determine the process id of a visual studio application

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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