VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • C#教程之c#不使用windows api函数打开我的电脑和获

打开我的电脑
System.Diagnostics.Process.Start("explorer.exe", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}");

第二个参数也可为完整路径,

通过查询注册表拿到的一些完整路径例子:

 

复制代码 代码如下:

public string GetWindowsPath(string path)
        {
            RegistryKey folders;
            folders = OpenRegistryPath(Registry.CurrentUser, @"\software\microsoft\windows\currentversion\explorer\shell folders");
            return folders.GetValue(path).ToString();
        }
private RegistryKey OpenRegistryPath(RegistryKey root, string s)
        {
            s = s.Remove(0, 1) + @"\";
            while (s.IndexOf(@"\") != -1)
            {
                root = root.OpenSubKey(s.Substring(0, s.IndexOf(@"\")));
                s = s.Remove(0, s.IndexOf(@"\") + 1);
            }
            return root;
        }

 


//调用
GetWindowsPath("关键字");

 

关键字比如:Windows用户桌面路径(Desktop),Windows用户字体目录路径(Fonts),Windows用户网络邻居路径(Nethood),Windows用户我的文档路径(Personal)...

具体的在注册表里面查找.

 以上是直接打开我的电脑的方法,当然也可以直接获取我的电脑的驱动器,方法如下:

 

复制代码 代码如下:

DriveInfo[] allDrives = DriveInfo.GetDrives();

 

foreach (DriveInfo d in allDrives)
{

messagebox.show(d.RootDirectory.FullName+"启动器所有信息在DriveInfo对象里都能找到");
messagebox.show(驱动器的类型+DriveTypeToCH(d.DriveType.ToString()));

}

 

这里就要说到启动器的类型了

 

复制代码 代码如下:

#region 驱动类型转换
        /// <summary>
        /// 驱动类型转换
        /// </summary>
        /// <param name="_String"></param>
        /// <returns></returns>
        private string DriveTypeToCH(string _String)
        {
            string ToCh = "";
            switch (_String.ToLower())
            {
                case "unknown":
                    ToCh = "其它";
                    break;
                case "removable":
                    ToCh = "移动设备";
                    break;
                case "fixed":
                    ToCh = "硬盘";
                    break;
                case "network":
                    ToCh = "网络硬盘";
                    break;
                case "cdrom":
                    ToCh = "CD-ROM";
                    break;
                case "ram":
                    ToCh = "RAM磁盘";
                    break;
                case "norootdirectory":
                    ToCh = "";
                    break;
                default:
                    break;
            }
            return ToCh;
        }
        #endregion

 

也可以通过windows api得到,我还是更喜欢这种方法


相关教程