Recent

Author Topic: Searching the registry for a particular PCI bus device?  (Read 2312 times)

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Searching the registry for a particular PCI bus device?
« on: April 09, 2019, 10:49:02 pm »
I have some code that searches for a particular device on the PCI bus, by VEN_abcd&DEV_wxyz

This is what interrogates the registry:-

Code: Pascal  [Select][+][-]
  1. uses registry
  2. var
  3.   Registry: TRegistry;
  4.   Key: String;
  5.   strl1: TStringList;        
  6. begin
  7.   Registry := TRegistry.Create;
  8.   Key:='\SYSTEM\CurrentControlSet\Enum\PCI';
  9.   strl1:=TStringList.Create;
  10.   strl1.Clear;
  11.   try
  12.     Registry.RootKey := HKEY_LOCAL_MACHINE;
  13.     if Registry.OpenKeyReadOnly(Key) then
  14.     begin
  15.       Registry.GetKeyNames(strl1);
  16.     end;
  17.   finally
  18.     Registry.Free;
  19.   end;
  20.  
after this you have a stringlist full of PCI identifiers with the VEN and DEV characters etc in a fixed place on each line.

I am getting a 1/2 % failure rate (as in 1 in 200) because when you put a device into a Windows PC it generates an entry in the above list, but if you then remove the device, the entry remains.

In other words this becomes the list of PCI devices that have ever been in the computer, not the one that are there right now.

Windows Device Manager can tell the difference because you only see the list of currently installed stuff but if you do View then Show Hidden Devices then you get all of them.

Is there a simple way if I can tell from within an FPC program whether a PCI device is actually there, right now?

JimD

  • Jr. Member
  • **
  • Posts: 62
Re: Searching the registry for a particular PCI bus device?
« Reply #1 on: May 25, 2019, 10:36:13 pm »
I have no idea but I ran across the following.
It appears to probe the BIOS to find PCI devices.
However it doesn't qualify as 'simple'.
https://github.com/OS2World/UTIL-HARDWARE-PCI-AGP_bus_sniffer/tree/master/src
Perhaps it could be adapted for your use, not sure.

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: Searching the registry for a particular PCI bus device?
« Reply #2 on: May 26, 2019, 04:42:54 am »
Is there a simple way if I can tell from within an FPC program whether a PCI device is actually there, right now?
According to this devpkey-device-configflags and const from RegStr.h:
Code: C  [Select][+][-]
  1. #define CONFIGFLAG_DISABLED             0x00000001      // Set if disabled
  2. #define CONFIGFLAG_REMOVED              0x00000002      // Set if a present hardware enum device deleted
  3. #define CONFIGFLAG_MANUAL_INSTALL       0x00000004      // Set if the devnode was manually installed
  4. #define CONFIGFLAG_IGNORE_BOOT_LC       0x00000008      // Set if skip the boot config
  5. #define CONFIGFLAG_NET_BOOT             0x00000010      // Load this devnode when in net boot
  6. #define CONFIGFLAG_REINSTALL            0x00000020      // Redo install
  7. #define CONFIGFLAG_FAILEDINSTALL        0x00000040      // Failed the install
  8. #define CONFIGFLAG_CANTSTOPACHILD       0x00000080      // Can't stop/remove a single child
  9. #define CONFIGFLAG_OKREMOVEROM          0x00000100      // Can remove even if rom.
  10. #define CONFIGFLAG_NOREMOVEEXIT         0x00000200      // Don't remove at exit.
  11. #define CONFIGFLAG_FINISH_INSTALL       0x00000400      // Complete install for devnode running 'raw'
  12. #define CONFIGFLAG_NEEDS_FORCED_CONFIG  0x00000800      // This devnode requires a forced config
  13. #if defined(REMOTE_BOOT)
  14. #define CONFIGFLAG_NETBOOT_CARD         0x00001000      // This is the remote boot network card
  15. #endif // defined(REMOTE_BOOT)
  16. #define CONFIGFLAG_PARTIAL_LOG_CONF     0x00002000      // This device has a partial logconfig
  17. #define CONFIGFLAG_SUPPRESS_SURPRISE    0x00004000      // Set if unsafe removals should be ignored
  18. #define CONFIGFLAG_VERIFY_HARDWARE      0x00008000      // Set if hardware should be tested for logo failures
  19. #define CONFIGFLAG_FINISHINSTALL_UI     0x00010000      // Show the finish install wizard pages for the installed device.
  20. #define CONFIGFLAG_FINISHINSTALL_ACTION 0x00020000      // Call installer with DIF_FINISHINSTALL_ACTION in client context.
  21.  
  22. #define CSCONFIGFLAG_BITS               0x00000007      // OR of below bits
  23. #define CSCONFIGFLAG_DISABLED           0x00000001      // Set if
  24. #define CSCONFIGFLAG_DO_NOT_CREATE      0x00000002      // Set if
  25. #define CSCONFIGFLAG_DO_NOT_START       0x00000004      // Set if
The easiest way is to leave only those with ConfigFlags=0.

 

TinyPortal © 2005-2018