C#获取当前程序运行环境信息
2021-01-16 18:13
标签:foreach basedir 用户 and spl ORC tle pos dir 复制自:C# 使用Environment获取当前程序运行环境相关信息 C#获取当前程序运行环境信息 标签:foreach basedir 用户 and spl ORC tle pos dir 原文地址:https://www.cnblogs.com/Tpf386/p/12213085.htmlstring basedir = AppDomain.CurrentDomain.BaseDirectory;//获取程序运行的路径
string resdir = string.Empty;
if (!string.IsNullOrWhiteSpace(basedir))
{
string[] paths = basedir.Split(‘\\‘);
for (int i = 0; i 2; i++)
{
resdir += paths[i] + "\\";
}
}
string item0 = "程序运行的上上层路径:" + resdir;
string item1 = "程序运行目录:" + Environment.CurrentDirectory;
string item2 = "操作系统的换行符是:" + Environment.NewLine;
string item3 = Environment.Is64BitOperatingSystem ? "64位操作系统" : "32位操作系统";
string item4 = Environment.Is64BitProcess ? "64位进程" : "32位进程";
string item5 = "当前系统版本:" + Environment.OSVersion;
string item6 = "CLR版本:" + Environment.Version.ToString();
string item8 = "当前计算机主板名字:" + Environment.MachineName;
string item9 = "当前计算机处理器数目:" + Environment.ProcessorCount;
string item10 = "操作系统启动后已运行:" + Environment.TickCount / 1000 / 3600 + "小时";
string item11 = "当前程序(该进程)的命令行:" + Environment.CommandLine;
string item12 = "当前使用操作系统的用户:" + Environment.UserName;
string item13 = "当前系统的逻辑桌面:" + Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string item14 = "当前系统的物理桌面:" + Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string item15 = "当前程序启动的命令行参数:";
string[] args2 = Environment.GetCommandLineArgs();
foreach (string item in args2)
{
item15 += item + "\t";
}
string item16 = "逻辑盘符有:";
string[] logicdrive = Environment.GetLogicalDrives();
foreach (var item in logicdrive)
{
item16 += item + "\t";
}
Console.ReadKey();
上一篇:C#快捷菜单
下一篇:windows 图标设置