Click here to Skip to main content
Click here to Skip to main content

Show and Hide Drive Using Registry in C#

By , 15 Oct 2012
Rate this:
Please Sign up or sign in to vote.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Gun Gun Febrianza
CEO Technology Pandawa
Indonesia Indonesia
No Biography provided
Follow on   Twitter

Comments and Discussions

 
Questionstatic number of drives PinmemberMaster Ab25-Mar-13 11:20 
GeneralMy vote of 5 PinmemberProgramFOX24-Oct-12 6:06 
GeneralRe: My vote of 5 Pinmember Gun Gun Febrianza24-Oct-12 6:09 
GeneralMy vote of 4 PinmemberJohn Brett16-Oct-12 21:12 
GeneralRe: My vote of 4 PinmemberGun Gun Febrianza17-Oct-12 0:08 
QuestionDrive lock Pinmemberhazeleekaizera15-Oct-12 23:11 
AnswerRe: Drive lock PinmemberGun Gun Febrianza15-Oct-12 23:20 
GeneralRe: Drive lock Pinmemberhazeleekaizera16-Oct-12 17:03 
GeneralRe: Drive lock PinmemberGun Gun Febrianza16-Oct-12 17:08 
GeneralMy vote of 5 Pinmemberhazeleekaizera15-Oct-12 23:10 
GeneralRe: My vote of 5 PinmemberGun Gun Febrianza15-Oct-12 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 16 Oct 2012
Article Copyright 2012 by Gun Gun Febrianza
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid