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:
- Value 4 using for hide drive = C
- Value 8 using for hide drive = D
- Value 10 using for hide drive = E
- Value 20 using for hide drive = F
- Value 40 using for hide drive = G
- Value 80 using for hide drive = H
- Value 100 using for hide drive = I
- Value 200 using for hide drive = J
- Value 400 using for hide drive = K
- Value 800 using for hide drive = L
- Value 1000 using for hide drive = M
- Value 2000 using for hide drive = N
- Value 4000 using for hide drive = O
- Value 8000 using for hide drive = P
- Value 10000 using for hide drive = Q
- Value 20000 using for hide drive = R
- Value 40000 using for hide drive = S
- Value 80000 using for hide drive = T
- Value 100000 using for hide drive = U
- Value 200000 using for hide drive = V
- Value 400000 using for hide drive = W
- Value 800000 using for hide drive = Y
- Value 1000000 using for hide drive = X
- Value 2000000 using for hide drive = Z
- 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' :
try
{
if (comboBox1.SelectedItem == "C")
{
string nodrive = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
RegistryKey rKey1 = Registry.CurrentUser.CreateSubKey(nodrive);
rKey1.SetValue("NoDrives",
Convert.ToInt32("4", 16), RegistryValueKind.DWord);
rKey1.Close();
ploading();
MessageBox.Show("Drive " + comboBox1.Text +
":\\ successful concealed ", "Drive Conceal",
MessageBoxButtons.OK, MessageBoxIcon.Information);
listBox1.Items.Add("Drive " + comboBox1.Text + ":\\ Hidden");
listBox1.Items.Add("On " + currentDay);
listBox1.Items.Add("");
restart();
}
You can view more code in the zip file, and the below code is the code for restart()
method:
private void restart()
{
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