C# 获取程序当前文件夹

来源:互联网 发布:北京 数据恢复 编辑:程序博客网 时间:2024/05/17 23:46
  1. Application.StartupPath     //如何获取当前进程所属程序的文件夹位置   (窗体中使用)
  2. ( label16.Text=Application.StartupPath;)
  3.   Environment.SystemDirectory;         //获取系统目录   
  4.   Environment.CurrentDirectory;       //获取当前目录    (类中使用)
  5.     
  6.   //获取进程数组==模块信息   
  7.   Process[]   allProcesses   =   Process.GetProcesses();   
  8.   foreach(Process   p   in   allProcesses)   
  9.   {   
  10.           if(p.ProcessName.Equals("Idle"))   
  11.           {   
  12.                   continue;   
  13.           }   
  14.           labelPN.Text     =   theNode.processInfo.ProcessName;     //进程名称   
  15.           labelPID.Text   =   theNode.processInfo.Id.ToString();//进程ID   
  16.           labelSO.Text     =   theNode.processInfo.StartTime.Date.ToString();//进程开始时间   
  17.           labelNOT.Text   =   theNode.processInfo.Threads.Count.ToString();   //线程数目   
  18.           ProcessModuleCollection   allModules   =   null;   
  19.           try   
  20.           {   
  21.   allModules   =   p.Modules;   
  22.           }   
  23.           catch   
  24.           {   
  25.   continue;   
  26.           }   
  27.           ProcessModule[]   modules   =   new   ProcessModule[allModules.Count];   
  28.           int   i   =   0;   
  29.           foreach(ProcessModule   m   in   allModules)   
  30.           {   
  31.   modules.SetValue(m,   i++);   
  32.           }   
  33.   labelMN.Text   =   theNode.moduleInfo.ModuleName;   
  34.   labelCN.Text   =   theNode.moduleInfo.FileVersionInfo.CompanyName;   
  35.   labelLFF.Text   =   theNode.moduleInfo.FileVersionInfo.FileName;   
  36.   labelFV.Text   =   theNode.moduleInfo.FileVersionInfo.FileVersion;   
  37.   if(!theNode.moduleInfo.FileVersionInfo.FileDescription.Equals(""))   
  38.   labelFD.Text   =   theNode.moduleInfo.FileVersionInfo.FileDescription;   
  39.   else   
  40.   labelFD.Text   =   "<None>";   
  41.   DateTime   timestamp   =   File.GetCreationTime(theNode.moduleInfo.FileVersionInfo.FileName);   
  42.   labelFT.Text   =   timestamp.ToString();   
  43.   FileInfo   fileInfo   =   new   FileInfo(theNode.moduleInfo.FileVersionInfo.FileName);   
  44.   labelFS.Text   =   fileInfo.Length.ToString();   
  45.   }   
  46.     
原创粉丝点击