Click here to Skip to main content
15,881,768 members
Articles / Security
Tip/Trick

Show and Hide Drive Using Registry in C#

Rate me:
Please Sign up or sign in to vote.
4.86/5 (5 votes)
15 Oct 2012CPOL2 min read 42K   3.2K   11   17
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:

C#
using Microsoft.Win32;
using System.Diagnostics;

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

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:

C#
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)


Written By
CEO Techno Camo
Indonesia Indonesia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionunhiding Pin
Member 1471446112-Jan-20 19:08
Member 1471446112-Jan-20 19:08 
Questionc# Pin
sohail naseer24-Jul-14 8:41
sohail naseer24-Jul-14 8:41 
AnswerRe: c# Pin
Gun Gun Febrianza30-Jul-14 10:26
Gun Gun Febrianza30-Jul-14 10:26 
QuestionHide - Unhide USB drives Pin
ArchanaDamahe30-Jun-14 0:39
ArchanaDamahe30-Jun-14 0:39 
AnswerRe: Hide - Unhide USB drives Pin
Gun Gun Febrianza30-Jul-14 10:30
Gun Gun Febrianza30-Jul-14 10:30 
Questionstatic number of drives Pin
Abdullah Mughal25-Mar-13 11:20
Abdullah Mughal25-Mar-13 11:20 
AnswerRe: static number of drives Pin
Gun Gun Febrianza30-Jul-14 10:28
Gun Gun Febrianza30-Jul-14 10:28 
GeneralMy vote of 5 Pin
Thomas Daniels24-Oct-12 6:06
mentorThomas Daniels24-Oct-12 6:06 
GeneralRe: My vote of 5 Pin
Gun Gun Febrianza24-Oct-12 6:09
Gun Gun Febrianza24-Oct-12 6:09 
GeneralMy vote of 4 Pin
John Brett16-Oct-12 21:12
John Brett16-Oct-12 21:12 
GeneralRe: My vote of 4 Pin
Gun Gun Febrianza17-Oct-12 0:08
Gun Gun Febrianza17-Oct-12 0:08 
QuestionDrive lock Pin
hazeleekaizera15-Oct-12 23:11
hazeleekaizera15-Oct-12 23:11 
AnswerRe: Drive lock Pin
Gun Gun Febrianza15-Oct-12 23:20
Gun Gun Febrianza15-Oct-12 23:20 
GeneralRe: Drive lock Pin
hazeleekaizera16-Oct-12 17:03
hazeleekaizera16-Oct-12 17:03 
GeneralRe: Drive lock Pin
Gun Gun Febrianza16-Oct-12 17:08
Gun Gun Febrianza16-Oct-12 17:08 
GeneralMy vote of 5 Pin
hazeleekaizera15-Oct-12 23:10
hazeleekaizera15-Oct-12 23:10 
Vote 5, nice article brother Big Grin | :-D
GeneralRe: My vote of 5 Pin
Gun Gun Febrianza15-Oct-12 23:23
Gun Gun Febrianza15-Oct-12 23:23 

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

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