No lo he probado, pero prueba esto a ver:
Código Delphi
[-]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
GUID_DEVINTERFACE_USB: TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}';
DIF_PROPERTYCHANGE = $12;
function SetupDiSetClassInstallParams(DeviceInfoSet: HDEVINFO;
DeviceInfoData: PSP_DEVINFO_DATA; ClassInstallParams: PSP_CLASSINSTALL_HEADER;
ClassInstallParamsSize: DWORD): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiSetClassInstallParamsW';
function SetupDiCallClassInstaller(InstallFunction: DI_FUNCTION;
DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA): BOOL; stdcall;
external 'Setupapi.dll' name 'SetupDiCallClassInstaller';
procedure DisableUSB;
var
DeviceInfoSet: HDEVINFO;
DeviceInfoData: SP_DEVINFO_DATA;
ClassInstallParams: TSPPropChangeParams;
begin
DeviceInfoSet := SetupDiGetClassDevs(@GUID_DEVINTERFACE_USB, nil, 0, DIGCF_PRESENT);
if DeviceInfoSet <> INVALID_HANDLE_VALUE then
begin
try
ZeroMemory(@DeviceInfoData, SizeOf(SP_DEVINFO_DATA));
DeviceInfoData.cbSize := SizeOf(SP_DEVINFO_DATA);
if SetupDiEnumDeviceInfo(DeviceInfoSet, 0, DeviceInfoData) then
begin
ZeroMemory(@ClassInstallParams, SizeOf(TSPPropChangeParams));
ClassInstallParams.ClassInstallHeader.cbSize := SizeOf(TSPPropChangeParams);
ClassInstallParams.ClassInstallHeader.InstallFunction := DIF_PROPERTYCHANGE;
ClassInstallParams.Scope := DICS_FLAG_GLOBAL;
ClassInstallParams.StateChange := DICS_DISABLE;
if not SetupDiSetClassInstallParams(DeviceInfoSet, @DeviceInfoData,
@ClassInstallParams.ClassInstallHeader, SizeOf(TSPPropChangeParams)) then
begin
ShowMessage('Error calling SetupDiSetClassInstallParams');
end
else
begin
if not SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DeviceInfoSet, @DeviceInfoData) then
begin
ShowMessage('Error calling SetupDiCallClassInstaller');
end;
end;
end
else
begin
ShowMessage('Error enumerating device information');
end;
finally
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
end;
end
else
begin
ShowMessage('Error getting device information set');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DisableUSB;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
end;
end.