System.Diagnostics.Process.GetExePath C# (CSharp) Method

GetExePath() private static method

Gets the path to the current executable, or null if it could not be retrieved.
private static GetExePath ( ) : string
return string
        private static string GetExePath()
        {
            return Interop.libproc.proc_pidpath(Interop.Sys.GetPid());
        }

Usage Example

        /// <summary>Gets an array of module infos for the specified process.</summary>
        /// <param name="processId">The ID of the process whose modules should be enumerated.</param>
        /// <returns>The array of modules.</returns>
        internal static ProcessModuleCollection GetModules(int processId)
        {
            ProcessModuleCollection modules = Interop.procfs.ParseMapsModules(processId) ?? new(capacity : 0);

            // Move the main executable module to be the first in the list if it's not already
            if (Process.GetExePath(processId) is string exePath)
            {
                for (int i = 0; i < modules.Count; i++)
                {
                    ProcessModule module = modules[i];
                    if (module.FileName == exePath)
                    {
                        if (i > 0)
                        {
                            modules.RemoveAt(i);
                            modules.Insert(0, module);
                        }
                        break;
                    }
                }
            }

            // Return the set of modules found
            return(modules);
        }
All Usage Examples Of System.Diagnostics.Process::GetExePath