using System.Runtime.InteropServices;
#region
/// <summary> /// 取exe文件绝对路径 /// </summary> /// <param name="hModule"></param> /// <param name="lpFileName"></param> /// <param name="nSize"></param> /// <returns></returns> [DllImport("kernel32")] public static extern int GetModuleFileName(IntPtr hModule, [Out] StringBuilder lpFileName,int nSize); #endregion
#region IntPtr processHandle = IntPtr.Zero; StringBuilder exeFileNamestrB = new StringBuilder(260); GetModuleFileName(processHandle, exeFileNamestrB, exeFileNamestrB.Capacity); #endregion