Solved

control if a process is being executed visual basic 2012

Posted on 2014-02-24
8
402 Views
Last Modified: 2014-02-24
Hi Experts,
We need to check if an exe file is already rinnung/working,
 if not then launch it from our App.
Important not to have two instances of the same App at the same time.

Can you help us with some source that can do this in visual basic ?
Regards!
0
Comment
Question by:rguillermo
8 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Is the exe file something you have coded, in other words can you modify it ?
0
 

Author Comment

by:rguillermo
Comment Utility
We I think we can modify the source... its a legacy App.. but pretty much used today. Works just fine.
0
 
LVL 21

Assisted Solution

by:Craig Wagner
Craig Wagner earned 167 total points
Comment Utility
The following will tell you if Excel is running. Replace "excel" with the name of the process you're looking for.

Dim isProcessRunning = Process.GetProcesses().Any(Function(p) p.ProcessName.Equals("excel", StringComparison.OrdinalIgnoreCase))

Open in new window

0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 167 total points
Comment Utility
Use Process.GetProcessesByName():
        Dim executable As String = "c:\some folder\path\file.exe"
        If Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(executable)).Length = 0 Then
            Process.Start(executable)
        End If

Open in new window

*Note that you pass just the EXE name without the path and without the .exe part.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>Important not to have two instances of the same App at the same time.

The only way I know of to be certain only instance is running is to modify the app so that once it is started it checks to see if itself is already running and then closes the instance that has just started.
pseudo code:
main()
{
  If(!AlreadyRunning())  //if it is already running then the current startup code is not run
  {
    //current startup code
  }
}
0
 
LVL 32

Assisted Solution

by:sarabande
sarabande earned 166 total points
Comment Utility
to add to before comment:

the AlreadyRunning function could be performed by using a named mutex. a mutex is a system resource which would be available as long as there is a program which has a handle of it. so a program that claims a handle of the mutex by name can find out whether it created the mutex or whether there is another program that created the mutex before. if that is the case the new program would exit.

the vb code could be like (not tested):

Imports System.Threading

Dim objMutex As Mutex

objMutex = New Mutex(False, "Use_Here_a_Unique_Name_No_Spaces")
If objMutex.WaitOne(0, False) = False Then
       objMutex.Close()
       objMutex = Nothing
       MessageBox.Show("Instance already running")
       End
 End If
 'if you get to this point it is the first (and only) instance
      'continue with app

Open in new window


Sara
0
 

Author Closing Comment

by:rguillermo
Comment Utility
Thank you !!!
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Odd choice of answers unless it isn't so important not to have two instances running after all.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now