Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net, find parent process exe name

Posted on 2009-07-14
2
Medium Priority
?
953 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
[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 Comments
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 2000 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

Industry Leaders: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

688 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