[C#][VB.NET]查询操作系统所在的磁盘位置

查询操作系统所在的磁盘位置


在蓝色小铺有人发问要如何查询操作系统的所在位置,在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=

原文:大专栏  [C#][VB.NET]查询操作系统所在的磁盘位置


猜你喜欢

转载自www.cnblogs.com/chinatrump/p/11518131.html