Solved

vb.net, find parent process exe name

Posted on 2009-07-14
2
912 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# HTTP GET method sample code 3 39
Receiving a string from a WebService Push 21 32
SQL Login 17 38
Visual Studio TFS - how do I check in my code? 2 28
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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

914 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

16 Experts available now in Live!

Get 1:1 Help Now