[C#][VB.NET]查詢作業系統所在的磁碟位置

  • 10848
  • 0
  • 2010-08-02

查詢作業系統所在的磁碟位置

在藍色小舖有人發問要如何查詢作業系統的所在位置,在VB6的年代,可以參考此網頁有非常詳細的解說

http://sunh.hosp.ncku.edu.tw/~cww/html/sysprosystem.html

而在.NET中,可以透過Environment class 來得到系統資料夾的位置

有興趣的可以參考

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

程式碼 VB.NET

        Dim Str = System.Environment.GetEnvironmentVariable("SystemRoot")
        Dim dir = Microsoft.VisualBasic.Left(Str, 2)
        MessageBox.Show("作業系統在" + dir)

程式碼 C#

                string str = System.Environment.GetEnvironmentVariable("SystemRoot");
                string dir = str.Substring(0, 2);
                MessageBox.Show("作業系統在" + dir);

 參考

http://www.blueshop.com.tw/board/show.asp?subcde=BRD20090217182608I60&fumcde=