c#中如何获取本机用户名、MAC地址、IP地址、硬盘ID、CPU序列号、系统名称、物理内存
摘要:我们在利用C#开发桌面程序(Winform)程序的时候,经常需要获取一些跟系统相关的信息,以下这些代码获取能有些用处。c#中如何获取本机用户名、MAC地址、IP地址、硬盘ID、CPU序列号、系统名称、物理内存。首先需要引入命名空间:using System.Management;/// 操作系统的登录用户名:string GetUserName(){ try { string st = ""; ManagementClass mc = new ManagementClass("Win32_ComputerSystem"); Manageme...
阅读全文
C#中如何获取文件路径
摘要://获取包含清单的已加载文件的路径或 UNC 位置。 public static string sApplicationPath = Assembly.GetExecutingAssembly ( ).Location; //result: X:\xxx\xxx\xxx.dll (.dll文件所在的目录+.dll文件名) //获取当前进程的完整路径,包含文件名(进程名)。 string str = this.GetType ( ).Assembly.Location; //result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名) //获取新的 Proce
阅读全文