Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check if appliacation already running in vb.net

Posted on 2016-08-03
4
Medium Priority
?
222 Views
Last Modified: 2016-08-04
I have the following code  to launch an external program via a button

 Dim p As New System.Diagnostics.Process

        p.StartInfo.FileName = "C:\Program Files (x86)\Campaign Maintenance\MarketingCampaignFrontEnd.exe"

        p.start

Works fine except that if the button is clicked multiple times, multiple instances of the program are launched

I'd like to add code so that the application is only started if it is not already running
0
Comment
Question by:johnnyg123
[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
4 Comments
 
LVL 85
ID: 41741124
Perhaps the "Make Single Instance Application" option would work for you? That's found in the My Project >> Application section.

MSDN article on the property: https://msdn.microsoft.com/en-us/library/8fz4ssw2(v=vs.100).aspx

Of course, this won't stop UserA on MachineA from running their local instance while UserB on MachineB is running their own local instance.
0
 

Author Comment

by:johnnyg123
ID: 41741196
Thanks for the response.....I think I need to explain a bit further what I am looking for


I wasn't looking on how to keep multiple instances of the vb.net application from being launched

The vb.net application has a "Main Menu" form with many buttons on it

One of the buttons will launch an external application

My question was regarding checking to see if an instance of the external application was already running.

I believe it is possible to check using a shell command but I saw something that gave me the impression that System.Diagnostics.Process  should be used  instead

Hope that better explains what I am looking for
0
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 41741269
What you want to do is get a list of the current processes that are running on the computer and compare them to the process you want to start.  If the process is not found in the list, then you can start the process; otherwise perform the set of tasks, if any, to properly handle the process running already.

In other words -
Module Module1
	Sub Main()
		' Note the usage of NOTEPAD.  This is because GetProcessByName 
		' uses the Friendly Name of the process.
		If Not IsProcessRunning("NOTEPAD") Then
			Process.Start("NOTEPAD.EXE")
			Console.WriteLine("Notepad started...")
		Else
			Console.WriteLine("Notepad is running...")
		End If
		Console.ReadLine()
	End Sub

	Function IsProcessRunning(name As String)
		Return Process.GetProcessesByName(name).Length > 0
	End Function
End Module

Open in new window

Will produce the following output with notepad not currently running -Capture.JPGAnd with notepad already running -Capture.JPGIf you want it to show the running instance, then you have a variety of methods that can be used, but it's pretty standard to use the Windows API to get the window handle, activate it if needed and set as the foreground window.

-saige-
0
 

Author Closing Comment

by:johnnyg123
ID: 41742568
Thanks

Exactly what I was looking for
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 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