c does not use the windows api function to open my computer and get the computer drive information

  • 2020-05-27 06:56:34
  • OfStack

Turn on my computer
System.Diagnostics.Process.Start("explorer.exe", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}");

The second parameter can also be the full path,

Some examples of full paths obtained by querying the registry:

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;

// call 
GetWindowsPath(" The keyword ");

Keywords such as :Windows user desktop path (Desktop),Windows user font directory path (Fonts),Windows user network neighbor path (Nethood),Windows user my document path (Personal)...

Look it up in the registry.

Above is the method to open my computer directly, of course, you can also directly access my computer's drive, the method is as follows:

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
messagebox.show(d.RootDirectory.FullName+" Starter all information in DriveInfo It can be found in objects ");
messagebox.show( Type of drive +DriveTypeToCH(d.DriveType.ToString()));

This is where the type of starter comes in

#region  Drive type conversion 
        /// <summary>
        ///  Drive type conversion 
        /// </summary>
        /// <param name="_String"></param>
        /// <returns></returns>
        private string DriveTypeToCH(string _String)
            string ToCh = "";
            switch (_String.ToLower())
                case "unknown":
                    ToCh = " other ";
                case "removable":
                    ToCh = " Mobile devices ";
                case "fixed":
                    ToCh = " The hard disk ";
                case "network":
                    ToCh = " The network hard disk ";
                case "cdrom":
                    ToCh = "CD-ROM";
                case "ram":
                    ToCh = "RAM disk ";
                case "norootdirectory":
                    ToCh = "";
            return ToCh;

It's also available through windows api, which I prefer

Related articles: