Registriert seit: 22. Jan 2008
Ort: Erfurt
958 Beiträge
Delphi 7 Enterprise
|
AW: USB-Ports deaktivieren&aktivieren in Delphi 7
28. Sep 2011, 14:50
Hallo,
unter XP habe ich es soo gemacht..obs unter Windows 7 auch so geht..weiss ich nicht genau.
Delphi-Quellcode:
...
uses setupapi;
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;
Gruss Kaki
Repeat Until true=false;
|
|
Zitat
|