C#取exe文件绝对路径

时间:2020-11-06 01:57:04   收藏:0   阅读:28

 

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

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!