Answers for "c# process getting the path of a process"

C#
1

get program path c#

using System;
class Program
{
  static void Main(string[] args)
  {
  string path;
  path = AppDomain.CurrentDomain.BaseDirectory;
  }
}
Posted by: Guest on March-03-2021
0

c# get process file location

public static string GetProcessPath(int processId)
{
    string MethodResult = "";
    try
    {
        string Query = "SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = " + processId;

        using (ManagementObjectSearcher mos = new ManagementObjectSearcher(Query))
        {
            using (ManagementObjectCollection moc = mos.Get())
            {
                string ExecutablePath = (from mo in moc.Cast<ManagementObject>() select mo["ExecutablePath"]).First().ToString();

                MethodResult = ExecutablePath;

            }

        }

    }
    catch //(Exception ex)
    {
        //ex.HandleException();
    }
    return MethodResult;
}
Posted by: Guest on June-24-2021

Code answers related to "c# process getting the path of a process"

C# Answers by Framework

Browse Popular Code Answers by Language