Delphi Can

Orjinalini görmek için tıklayınız: joystic kontrolu
Şu anda (Arşiv) modunu görüntülemektesiniz. Orjinal Sürümü Görüntüle internal link
arkadaslar usb direksiyon seti var bilgisayarda yaris oyunu icin bir oyun makinasinda revizyon yapmak istiyorum. 
usb direksiyon portunu program ile bloke edip geri acabilirmiyiz. bu mumkunmu.

aslinda fiziksel olarak kontrol edebilirim usb data kablosunun Tx ucunu roleden gecirip joystick in kontrolunu alabilirim ama 
program ile yapmak istiyorum.

fiziksel yaptigimizda her seferinde yeni donanim bulundu seklinde donanim kuruluyor ben bunu istemiyorum
bilgisayar joystic i surekli gorsun ama kontrolu yazilimla benim elimden olsun.

derdimi tam olarak anlatabildim insallah.
saygilarimla
https://superuser.com/questions/502046/h...and-prompt

Download utility devcon from Microsoft.

Then, use it as follows: List all known USB devices:

devcon find USB*
Disable USB device:

devcon disable "USB\VID_xxxx&PID_yyyy"
Enable USB device:

devcon enable "USB\VID_xxxx&PID_yyyy"


ilgili exe yi gizli window ile shellexecute ile çalıştırabilirsiniz.

alternatif;

https://www.nirsoft.net/articles/disable..._line.html

usb donanımları almak;
https://blogs.embarcadero.com/quickly-en...n-windows/

usb hub u disable etmek;
https://groups.google.com/g/comp.lang.pa...c2sJ?pli=1


https://github.com/RRUZ/delphi-wmi-class...USBHub.pas
buradaki, SetPowerState(const PowerState : Word;const Time : TDateTime): Integer; test edilebilinir.

denenebilir?
https://www.tweakandtrick.com/2010/07/di...ur-pc.html
https://www.partitionwizard.com/partitio...win11.html
https://allusefulinfo.com/4-ways-to-disa...indows-pc/

bu reg anahtarlarının etkisini test etmek gerekir çalışıyorsa, delphi kısmı basittir.

denenebilinir.
uses
  Windows, SysUtils;

const
 GUID_DEVINTERFACE_USB_DEVICE: TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}';
 DIGCF_PRESENT = $00000002;
 SPDRP_DEVICEDESC = $00000000;
 CR_SUCCESS = $00000000;
 CM_DEVCAP_SURPRISEREMOVALOK = $00000004;
 DICS_FLAG_GLOBAL = $00000001;
 DIREG_DEV = $00000001;

function SetupDiGetClassDevsA(
 ClassGuid: PGUID;
 Enumerator: PAnsiChar;
 hwndParent: HWND;
 Flags: DWORD
): THandle; stdcall; external 'setupapi.dll' name 'SetupDiGetClassDevsA';

function SetupDiEnumDeviceInfo(
 DeviceInfoSet: THandle;
 MemberIndex: DWORD;
 DeviceInfoData: PSPDevInfoData
): LongBool; stdcall; external 'setupapi.dll' name 'SetupDiEnumDeviceInfo';

function SetupDiDestroyDeviceInfoList(
 DeviceInfoSet: THandle
): LongBool; stdcall; external 'setupapi.dll' name 'SetupDiDestroyDeviceInfoList';

function SetupDiGetDeviceRegistryPropertyA(
 DeviceInfoSet: THandle;
 DeviceInfoData: PSPDevInfoData;
 Property_: DWORD;
 PropertyRegDataType: PDWORD;
 PropertyBuffer: PByte;
 PropertyBufferSize: DWORD;
 RequiredSize: PDWORD
): LongBool; stdcall; external 'setupapi.dll' name 'SetupDiGetDeviceRegistryPropertyA';

function CM_Get_Device_IDA(
 DevInst: DWORD;
 Buffer: PAnsiChar;
 BufferLen: DWORD;
 Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Get_Device_IDA';

function CM_Locate_DevNodeA(
 DevInst: PDWORD;
 DevID: PAnsiChar;
 Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Locate_DevNodeA';

function CM_Get_DevNode_Status(
 Status: PDWORD;
 ProblemNumber: PDWORD;
 DevInst: DWORD;
 Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Get_DevNode_Status';

function CM_Get_DevNode_Registry_PropertyA(
 DevInst: DWORD;
 Property_: DWORD;
 RegDataType: PDWORD;
 Buffer: PVOID;
 BufferSize: PDWORD;
 Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Get_DevNode_Registry_PropertyA';

function CM_Set_DevNode_Registry_PropertyA(
 DevInst: DWORD;
 Property_: DWORD;
 Buffer: Pointer;
 BufferSize: DWORD;
 Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Set_DevNode_Registry_PropertyA';

function CM_Request_Device_EjectA(
 DevInst: DWORD;
 VetoType: PVetoType;
 VetoName: PAnsiChar;
 VetoNameSize: DWORD;
 Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Request_Device_EjectA';

type
 SP_DEVINFO_DATA = packed record
   cbSize: DWORD;
   ClassGuid: TGUID;
   DevInst: DWORD;
   Reserved: ULONG_PTR;
 end;

 PSPDevInfoData = ^SP_DEVINFO_DATA;

 VetoType = packed record
   case Integer of
     0: (VetoType: DWORD);
     1: (VetoDriver: array [0..19] of AnsiChar);
     2: (VetoName: array [0..259] of AnsiChar);
 end;
 PVetoType = ^VetoType;

procedure EnableUSBDevice(DeviceInstanceID: AnsiString);
var
 hDevInfo: THandle;
 DeviceInfoData: SP_DEVINFO_DATA;
 DevInst: DWORD;
 BufferSize: DWORD;
 ProblemNumber, Status: DWORD;
 Veto: VetoType;
begin
 hDevInfo := SetupDiGetClassDevsA(@GUID_DEVINTERFACE_USB_DEVICE, nil, 0, DIGCF_PRESENT);
 if hDevInfo <> INVALID_HANDLE_VALUE then
 try
   DeviceInfoData.cbSize := SizeOf(DeviceInfoData);
   DevInst := 0;
   while SetupDiEnumDeviceInfo(hDevInfo, DevInst, @DeviceInfoData) do
   begin
     BufferSize := 0;
     if CM_Get_Device_IDA(DeviceInfoData.DevInst, nil, 0, 0) = CR_SUCCESS then
     begin
       SetLength(DeviceInstanceID, BufferSize - 1);
       if CM_Get_Device_IDA(DeviceInfoData.DevInst, PAnsiChar(DeviceInstanceID), BufferSize, 0) = CR_SUCCESS then
         Break;
     end;
     Inc(DevInst);
   end;

   if DevInst <> MAXDWORD then
   begin
     Status := CM_Get_DevNode_Status(@Status, @ProblemNumber, DeviceInfoData.DevInst, 0);
     if (Status and DN_HAS_PROBLEM) = 0 then
     begin
       if (Status and DN_DISABLEABLE) <> 0 then
       begin
         Status := CM_Set_DevNode_Registry_PropertyA(
           DeviceInfoData.DevInst,
           CM_DEVCAP_SURPRISEREMOVALOK,
           @Status,
           SizeOf(Status),
           DICS_FLAG_GLOBAL
         );

         if Status = CR_SUCCESS then
         begin
           Status := CM_Request_Device_EjectA(DeviceInfoData.DevInst, @Veto, nil, 0, 0);
           if Status = CR_SUCCESS then
             Writeln('USB device has been enabled.');
         end;
       end
       else
         Writeln('USB device is not disableable.');
     end
     else
       Writeln('USB device has a problem and cannot be enabled.');
   end
   else
     Writeln('USB device not found.');
 finally
   SetupDiDestroyDeviceInfoList(hDevInfo);
 end
 else
   Writeln('Error getting device information.');
end;

begin
 try
   EnableUSBDevice(''); // Provide the appropriate DeviceInstanceID
 except
   on E: Exception do
     Writeln('An error occurred: ', E.Message);
 end;
end.

uses
  Windows, SysUtils;

// ... Gerekli Windows API fonksiyonlarını ve türleri burada tanımlayın ...

procedure EnableUSBDevice(DeviceInstanceID: AnsiString);
begin
 // ... Yukarıdaki örnek kodu buraya ekleyin ...
end;

procedure TForm1.EnableUSBButtonClick(Sender: TObject);
var
 DeviceInstanceID: AnsiString;
begin
 // Belirli bir USB cihazının DeviceInstanceID'sini buraya atayın
 DeviceInstanceID := '...';

 try
   EnableUSBDevice(DeviceInstanceID);
   ShowMessage('USB cihazı etkinleştirildi.');
 except
   on E: Exception do
     ShowMessage('Hata oluştu: ' + E.Message);
 end;
end;

procedure TForm1.DisableUSBButtonClick(Sender: TObject);
var
 DeviceInstanceID: AnsiString;
begin
 // Belirli bir USB cihazının DeviceInstanceID'sini buraya atayın
 DeviceInstanceID := '...';

 try
   DisableUSBDevice(DeviceInstanceID);
   ShowMessage('USB cihazı devre dışı bırakıldı.');
 except
   on E: Exception do
     ShowMessage('Hata oluştu: ' + E.Message);
 end;
end;


end.
cok tesekkurler hocam donanim kismini halleder halettemez butun yontemleri deniyecegim. saygilar