Tuesday, April 28, 2009

Enable & Disable Mass( pen drive) Storage through C#.net

//this code is use to create a program to enable and disable Mass storage without disabling USB (you can use usb mouse after disabling the mass storage )
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace USBGame
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void btnenable_Click(object sender, EventArgs e)
{
const string keyName = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR";

// int tLong = (int )Registry.GetValue(keyName, "Start",0);
Registry.SetValue(keyName, "Start", "00000003");
MessageBox.Show("USB MassStorage Enabled");

}

private void btndisable_Click(object sender, EventArgs e)
{
const string keyName = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR";

// int tLong = (int )Registry.GetValue(keyName, "Start",0);
Registry.SetValue(keyName, "Start", "00000004");
MessageBox.Show("USB MassStorage Disabled");
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
MessageBox.Show("Developed By Rajesh Kumar Rolen");
}

private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("It will disable your all USB ports and you will not able to use any USB Mass Storage or Mouse or Keyboard", "Disable USB Completely", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
const string keyName = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR";

// int tLong = (int )Registry.GetValue(keyName, "Start",0);
Registry.SetValue(keyName, "Start", "00000005");
MessageBox.Show("USB Disabled Completely");
}
else
{
MessageBox.Show("Abbe Baaaaach Gaya Nahe to KeyBoard and Mouse dono he band ho jate");
}
}
}
}

Share This!


3 comments:

Anonymous said...

many thanks.you are genius.

anshul sharma said...

i am able to block the usb mass storage device but re-enabling it is not taking place."start DWORD in usbstor is converted into string
value on clicking disable button.now on clicking enable button, the string value is not reversed to binary value.and that is the problem.
plzz help me out.
thanx in advance.and really, this work is appreciable!

ADITYA said...

the disable works fine please tell me how to enable it. bcz your code is not working.

Powered By Blogger · Designed By Seo Blogger Templates