Solved

vb.net, find parent process exe name

Posted on 2009-07-14
2
916 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
ID: 24859215
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
ID: 24874085

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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