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

Monday, April 6, 2009

allow decimal values in textbox in c#.net windows forms.

to make textbox to allow decimal values in textbox in c#.net windows forms.

private void txtRate_KeyPress(object sender, KeyPressEventArgs e){ if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) && !(e.KeyChar.Equals('.')))
e.Handled =true;}


---------------------------VB.NET-------------------------------
Dim decexist As Boolean = False
If (CType(sender, TextBox).Text.IndexOf(".") > 0) And e.KeyChar.Equals("."c) Then
decexist = True
End If

If (Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not (e.KeyChar.Equals("."c))) Or decexist Then
e.Handled = True
End If
Read More
Powered By Blogger · Designed By Seo Blogger Templates