Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Show and Hide Drive Using Registry in C#

0.00/5 (No votes)
15 Oct 2012 1  
Show and hide your drive using software drive conceal

Introduction

In this tip, I will explain how to show and hide your drive using registry in C#, so we can keep/save our important and sensitive information by hiding our drive. We can hide some parts of the drive or hide the entire drive. Although it's not perfect for protecting our important and sensitive information, we can protect our important and sensitive information from people with little knowledge.

Background

Basically in this code, I will show you how to hide your drive in registry. We must create a subkey in HKEY_CURRENT_USER and this is the path Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer we must create DWORD 'NoDrives' with value 4. Value 4 is used for hiding drive 'C'.

And this is values information for hiding drive using registry:

  1. Value 4 using for hide drive = C
  2. Value 8 using for hide drive = D
  3. Value 10 using for hide drive = E
  4. Value 20 using for hide drive = F
  5. Value 40 using for hide drive = G
  6. Value 80 using for hide drive = H
  7. Value 100 using for hide drive = I
  8. Value 200 using for hide drive = J
  9. Value 400 using for hide drive = K
  10. Value 800 using for hide drive = L
  11. Value 1000 using for hide drive = M
  12. Value 2000 using for hide drive = N
  13. Value 4000 using for hide drive = O
  14. Value 8000 using for hide drive = P
  15. Value 10000 using for hide drive = Q
  16. Value 20000 using for hide drive = R
  17. Value 40000 using for hide drive = S
  18. Value 80000 using for hide drive = T
  19. Value 100000 using for hide drive = U
  20. Value 200000 using for hide drive = V
  21. Value 400000 using for hide drive = W
  22. Value 800000 using for hide drive = Y
  23. Value 1000000 using for hide drive = X
  24. Value 2000000 using for hide drive = Z
  25. Value 3ffffff used for hide = All Drive

Using the Code

Before using this code, we must import this namespace reference:

using Microsoft.Win32;
using System.Diagnostics;

This is a sample of some code to hide drive 'C' :

//button hide drive
try
{
    if (comboBox1.SelectedItem == "C")
    {
        //subkey nodrive in HKEY_CURRENT_USER
        string nodrive = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
        RegistryKey rKey1 = Registry.CurrentUser.CreateSubKey(nodrive);
        
        //create DWORD 'NoDrives' with value 4. for hiding drive C
        rKey1.SetValue("NoDrives", 
        Convert.ToInt32("4", 16), RegistryValueKind.DWord);
        rKey1.Close();
        
        //progressbarloading effect
        ploading();
        
        //give a message
        MessageBox.Show("Drive " + comboBox1.Text + 
        ":\\ successful concealed ", "Drive Conceal", 
        MessageBoxButtons.OK, MessageBoxIcon.Information);
        
        //add logs history
        listBox1.Items.Add("Drive " + comboBox1.Text + ":\\ Hidden");
        listBox1.Items.Add("On " + currentDay);
        listBox1.Items.Add("");
        
        //need restart to take effect
        restart();
    } 

You can view more code in the zip file, and the below code is the code for restart() method:

private void restart()
{
    // menghentikan process explorer
    Process p = new Process();
    foreach (System.Diagnostics.Process exe in System.Diagnostics.Process.GetProcesses())
    {
        if (exe.ProcessName == "explorer")
 
        exe.Kill();
    }
} 

Points of Interest

Hope this code will be useful for you and that you get benefited from this.
Happy programming and keep learning.

History

  • Drive conceal v.1.0

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here