unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, setupapi, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Disable_USB;
var hdev: HDEVINFO;
devinfo: TSPDevInfoData;
DriverInfoData: TSPDrvInfoDataA;
DriverInstallParams: TSPPropChangeParams;
ClassInstallParams:TSPPropChangeParams;
ClassInstallParamsSize: DWORD;
devInfoListDetail: TSPDevInfoListDetailDataA;
buffer:
Array [0..1024]
of char;
buffersize,dataType:DWORD;
status,problem:DWORD;
i,z:integer;
s:
string;
OK:Longbool;
begin
devinfo.cbSize:= sizeof(devinfo);
hdev:= SetupDiGetClassDevs(0,0,0,DIGCF_ALLCLASSES);
if (hdev =
NIL )
then
begin
Showmessage('
Unable to enumerate device');
exit;
end;
i:=0;
//Devices listen
repeat
Buffer[0]:=#0;
if not (SetupDiEnumDeviceInfo(hdev,i,devinfo))
then break;
if (GetLastError() = ERROR_NO_MORE_ITEMS)
then break;
if (SetupDiGetDeviceRegistryProperty(hdev,devinfo,SPDRP_DEVICEDESC,
@DataType,@Buffer[0],sizeof(Buffer),@BufferSize))
then
begin
s:=strpas(Buffer);
//suchen des speziellen Device
if pos('
USB Universal Host Controller',s)>0
then
begin
devInfoListDetail.cbSize:= sizeof(devInfoListDetail);
ClassInstallParams.Classinstallheader.cbSize:= sizeof(_SP_CLASSINSTALL_HEADER);
ClassInstallParams.Classinstallheader.Installfunction:=DIF_Propertychange;
// state disable setzen
ClassInstallParams.statechange:=DICS_Disable;
ClassInstallParams.Scope:=DICS_FLAG_CONFIGSPECIFIC;
ClassInstallParams.HWProfile:=0;
if SetupDiSetClassInstallParams(HDEV,@DevInfo,@ClassInstallParams.Classinstallheader,sizeof(ClassInstallParams))
then
begin
SetupDICallClassInstaller(DIF_PropertyChange,HDEV,@devinfo);
end else z:=Getlasterror;
end;
Buffer[0]:=#0;
end;
i:=i+1;
until false;
SetupDiDestroyDeviceInfoList(hdev);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Disable_USB();
ShowMessage('
deaktiviert');
end;
end.