DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

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");
}
}
}
}

2 comments:

Anonymous January 29, 2010 at 8:31 AM  

many thanks.you are genius.

ADITYA August 31, 2010 at 11:49 AM  

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

Post a Comment

About this blog

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Search This Blog