码迷,mamicode.com
首页 > Windows程序 > 详细

C#获取当前程序运行环境信息

时间:2020-01-19 12:26:27      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:foreach   basedir   用户   and   spl   ORC   tle   pos   dir   

 

复制自:C# 使用Environment获取当前程序运行环境相关信息

 

string basedir = AppDomain.CurrentDomain.BaseDirectory;//获取程序运行的路径
            string resdir = string.Empty;
            if (!string.IsNullOrWhiteSpace(basedir))
            {
                string[] paths = basedir.Split(\\);
                for (int i = 0; i < paths.Length - 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#获取当前程序运行环境信息

标签:foreach   basedir   用户   and   spl   ORC   tle   pos   dir   

原文地址:https://www.cnblogs.com/Tpf386/p/12213085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!