--> Enable Disable USB Write Protection by Delphi | Delphi Tips Trick

For Newbie

Tuesday, 15 November 2011

Enable Disable USB Write Protection by Delphi

| Tuesday, 15 November 2011
Trick to enable / disable USB Write Protection on Windows XP.

Declaration procedure:
const
key = 'SYSTEM \ ControlSet001 \ Control \ StorageDevicePolicies';

/ / Reading is a USB Write Protect On.
USBWriteProtectEnabled function: Boolean;
begin
Result: = False;
with TRegistry.Create do
begin
RootKey: = HKEY_LOCAL_MACHINE;
try
if OpenKey (key, False) then
begin
Result: = ReadBool ('WriteProtect');
end;
finally
free;
end;
end;
end;

/ / Change protection
USBWriteProtect procedure (const e: Boolean);
begin
with TRegistry.Create do
begin
RootKey: = HKEY_LOCAL_MACHINE;
try
if OpenKey (key, True) then
begin
WriteBool ('WriteProtect', e);
end;
finally
free;
end;
end;
end;

Example of implementation:
TForm1.FormCreate procedure (Sender: TObject);
begin
CheckBox1.Checked: = USBWriteProtectEnabled;
end;

TForm1.CheckBox1Click procedure (Sender: TObject);
begin
USBWriteProtect (CheckBox1.Checked);
end;

Add to Klause uses the unit Registry

Related Posts

No comments: