亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

C#中如何獲取系統環境變量

系統 4362 0

C#中獲取系統環境變量需要用到 Environment Class。其中 提供了有關當前環境和平臺的信息以及操作它們的方法。該 類不能被繼承。

?

以下代碼得到%systemdrive%的值,即“C:”

string sPath = Environment.GetEnvironmentVariable("systemdrive")

      string sPath = Environment.GetEnvironmentVariable("systemdrive");

Console.WriteLine(sPath);



//C:
    


以下是MSDN上Environment Class的Sample code。

http://msdn.microsoft.com/en-us/library/system.environment.aspx
?

以下代碼列出了當前系統的環境信息。

      // Sample for Environment class summary

using System;

using System.Collections;



class Sample 

{

    public static void Main() 

    {

    String str;

    String nl = Environment.NewLine;

//

    Console.WriteLine();

    Console.WriteLine("-- Environment members --");



//  Invoke this sample with an arbitrary set of command line arguments.

    Console.WriteLine("CommandLine: {0}", Environment.CommandLine);



    String[] arguments = Environment.GetCommandLineArgs();

    Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));



//  <-- Keep this information secure! -->

    Console.WriteLine("CurrentDirectory: {0}", Environment.CurrentDirectory);



    Console.WriteLine("ExitCode: {0}", Environment.ExitCode);



    Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted);



//  <-- Keep this information secure! -->

    Console.WriteLine("MachineName: {0}", Environment.MachineName);



    Console.WriteLine("NewLine: {0}  first line{0}  second line{0}  third line",

                          Environment.NewLine);



    Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());



    Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);



//  <-- Keep this information secure! -->

    Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory);



    Console.WriteLine("TickCount: {0}", Environment.TickCount);



//  <-- Keep this information secure! -->

    Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName);



    Console.WriteLine("UserInteractive: {0}", Environment.UserInteractive);



//  <-- Keep this information secure! -->

    Console.WriteLine("UserName: {0}", Environment.UserName);



    Console.WriteLine("Version: {0}", Environment.Version.ToString());



    Console.WriteLine("WorkingSet: {0}", Environment.WorkingSet);



//  No example for Exit(exitCode) because doing so would terminate this example.



//  <-- Keep this information secure! -->

    String query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";

    str = Environment.ExpandEnvironmentVariables(query);

    Console.WriteLine("ExpandEnvironmentVariables: {0}  {1}", nl, str);



    Console.WriteLine("GetEnvironmentVariable: {0}  My temporary directory is {1}.", nl,

                           Environment.GetEnvironmentVariable("TEMP"));



    Console.WriteLine("GetEnvironmentVariables: ");

    IDictionary	environmentVariables = Environment.GetEnvironmentVariables();

    foreach (DictionaryEntry de in environmentVariables)

        {

        Console.WriteLine("  {0} = {1}", de.Key, de.Value);

        }



    Console.WriteLine("GetFolderPath: {0}", 

                 Environment.GetFolderPath(Environment.SpecialFolder.System));



    String[] drives = Environment.GetLogicalDrives();

    Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));

    }

}

/*

This example produces results similar to the following:

(Any result that is lengthy or reveals information that should remain 

secure has been omitted and marked "!---OMITTED---!".)



C:\>env0 ARBITRARY TEXT



-- Environment members --

CommandLine: env0 ARBITRARY TEXT

GetCommandLineArgs: env0, ARBITRARY, TEXT

CurrentDirectory: C:\Documents and Settings\!---OMITTED---!

ExitCode: 0

HasShutdownStarted: False

MachineName: !---OMITTED---!

NewLine:

  first line

  second line

  third line

OSVersion: Microsoft Windows NT 5.1.2600.0

StackTrace: '   at System.Environment.GetStackTrace(Exception e)

   at System.Environment.GetStackTrace(Exception e)

   at System.Environment.get_StackTrace()

   at Sample.Main()'

SystemDirectory: C:\WINNT\System32

TickCount: 17995355

UserDomainName: !---OMITTED---!

UserInteractive: True

UserName: !---OMITTED---!

Version: !---OMITTED---!

WorkingSet: 5038080

ExpandEnvironmentVariables:

  My system drive is C: and my system root is C:\WINNT

GetEnvironmentVariable:

  My temporary directory is C:\DOCUME~1\!---OMITTED---!\LOCALS~1\Temp.

GetEnvironmentVariables: 

  !---OMITTED---!

GetFolderPath: C:\WINNT\System32

GetLogicalDrives: A:\, C:\, D:\



*/


    

C#中如何獲取系統環境變量


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 777奇米视频 | 在线免费观看中文字幕 | 亚洲精品不卡 | 久草在线首页 | 日本不卡一区二区三区 最新 | 国产永久| 日本精品一区二区三区视频 | 九九黄色网 | 久久精品影院一区二区三区 | 9热在线精品视频观看 | 国产网站麻豆精品视频 | 奇米网狠狠 | 在线欧美精品一区二区三区 | 精品综合久久久久97 | 精品国产一区二区三区四区色 | 亚欧精品一区二区三区四区 | 四虎b789ucom| 国产成人禁片免费观看视频 | 毛片网站大全 | 精品久久久久久久一区二区伦理 | 性www| 成人亚洲精品7777 | 久久www香蕉免费人成 | 91探花国产综合在线精品 | 狠狠色香婷婷久久亚洲精品 | 综合亚洲网 | 成人国产精品一级毛片视频 | 日本高清免费不卡视频 | 国产a级一级久久毛片 | 九九热欧美 | 苦瓜se影院在线视频网站 | 日日天天| 国产原创中文字幕 | 久久精品天堂 | 91久久精品国产亚洲 | 欧美日韩中文字幕在线手机版本 | 精品久久国产老人久久综合 | 国产午夜亚洲精品不卡福利 | 天天干亚洲| www.黄色网 | 精品久久香蕉国产线看观看亚洲 |