Solved

vb.net, find parent process exe name

Posted on 2009-07-14
2
910 Views
Last Modified: 2013-11-26
I need a function or way of feeding a function an exe name and it returns the parent exe name..
0
Comment
Question by:bluedragon99
2 Comments
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
Comment Utility
You can iterate through processes and find one (or MORE, of course!) that match a specific exe name, that is pretty easy.

 private string GetProc(string name)
    {
        var list = Process.GetProcesses();
        string output = "";
        foreach (Process p in list) {
            try
            {
                if (p.MainModule.FileName.Contains(name))
                {
                    output += p.ProcessName + "; ";
                }
            }
            catch (Exception ex)
            {
                output += ex.Message + "; ";
            }
        }
        return output;
    }

Note the try-catch - some of your attempts to derefence the MainModule may throw an exception, so this does not catch ALL of them.


Getting parent is a bit harder, see

http://stackoverflow.com/questions/394816/how-to-get-parent-process-in-net-in-managed-way
0
 
LVL 1

Author Comment

by:bluedragon99
Comment Utility

using System.Diagnostics;

PerformanceCounter pc = new PerformanceCounter("Process",

"Creating Process ID", Process.GetCurrentProcess().ProcessName);

return Process.GetProcessById((int)pc.NextValue());

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 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

7 Experts available now in Live!

Get 1:1 Help Now