Downloads:
Features:
- Control all USB ports ( Enable / Disable , Read & Write / Read only)
Notes:
- You must run the application as an admin!
- In app.manifest of your project change the requestedExecutionLevel from ” asInvoker ” to ” requireAdministrator “
C# Source Code:
- Main.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
using System; using System.Runtime.InteropServices; using Microsoft.Win32; using System.Windows.Forms; namespace USB_Controller { public partial class Main : Form { bool isAdmin; [DllImport("shell32")] static extern bool IsUserAnAdmin(); public Main() { InitializeComponent(); } private void Main_Load(object sender, EventArgs e) { isAdmin = IsUserAnAdmin(); if (isAdmin == false) { MessageBox.Show("Please run the application as Administrator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); groupBox1.Enabled = false; } else { try { string path1 = "SYSTEM\\CurrentControlSet\\services\\USBSTOR\\"; RegistryKey RK = Registry.LocalMachine.OpenSubKey(path1, true); string currentKey1 = RK.GetValue("Start").ToString(); if (currentKey1 == "3") { status.Text = "Status : All USB ports unlocked !"; Unlock.Enabled = false; } if (currentKey1 == "4") { status.Text = "Status : All USB ports locked !"; Lock.Enabled = false; } string check = "SYSTEM\\CurrentControlSet\\Control\\StorageDevicePolicies\\"; RegistryKey rkSubKey = Registry.LocalMachine.OpenSubKey(check, false); if (rkSubKey == null) { try { RegistryKey k = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Control\\StorageDevicePolicies"); k.SetValue("WriteProtect", "0", RegistryValueKind.DWord); StatusRW.Text = "Read & Write"; rdbReadWrite.Checked = true; rdbReadOnly.Checked = false; k.Close(); } catch { } } else { string path2 = "SYSTEM\\CurrentControlSet\\Control\\StorageDevicePolicies\\"; RegistryKey key = Registry.LocalMachine.OpenSubKey(path2, true); string currentkey2 = key.GetValue("WriteProtect").ToString(); if (currentkey2 == "1") { rdbReadWrite.Checked = false; rdbReadOnly.Checked = true; StatusRW.Text = "Read Only !"; } if (currentkey2 == "0") { rdbReadWrite.Checked = true; rdbReadOnly.Checked = false; StatusRW.Text = "Read & Write"; } } } catch { } } } private void Lock_Click(object sender, EventArgs e) { try { Unlock.Enabled = true; Lock.Enabled = false; string path = "SYSTEM\\CurrentControlSet\\services\\USBSTOR\\"; RegistryKey RK = Registry.LocalMachine.OpenSubKey(path, true); RK.SetValue("Start", "4", RegistryValueKind.DWord); status.Text = "Status : All USB ports locked !"; } catch (Exception ex) { MessageBox.Show("You should run the application as Adminstrator !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void Unlock_Click(object sender, EventArgs e) { try { Lock.Enabled = true; ; Unlock.Enabled = false; status.Text = "Status : All USB ports unlocked !"; string path = "SYSTEM\\CurrentControlSet\\services\\USBSTOR\\"; RegistryKey RK = Registry.LocalMachine.OpenSubKey(path, true); RK.SetValue("Start", "3", RegistryValueKind.DWord); } catch { MessageBox.Show("You should run the application as Adminstrator !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void rdbReadOnly_CheckedChanged(object sender, EventArgs e) { try { RegistryKey key; key = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Control\\StorageDevicePolicies"); key.SetValue("WriteProtect", "1", RegistryValueKind.DWord); StatusRW.Text = "Read Only !"; key.Close(); } catch { } } private void rdbReadWrite_CheckedChanged(object sender, EventArgs e) { try { RegistryKey key; key = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Control\\StorageDevicePolicies"); key.SetValue("WriteProtect", "0", RegistryValueKind.DWord); StatusRW.Text = "Read & Write"; key.Close(); } catch { } } } } |
- App.manifest
1 |
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> |
Screenshots:
Similar Apps:
Unknown
Contact: