Seite 1 von 1

alle hardware-PNPs des systems ermitteln

Verfasst: 28.01.2005 19:06
von bingo
anhand der PNPs wird die hardware des systemes "sichtbar":

Code: Alles auswählen

#DIGCF_PRESENT                     =   2 
#DIGCF_ALLCLASSES                  =   4 

hDeviceInfoSet = SetupDiGetClassDevs_(0,0,0,#DIGCF_PRESENT|#DIGCF_ALLCLASSES)

Structure SP_DEVINFO_DATA 
  cbSize.l 
  ClassGuid.GUID 
  DevInst.l 
  Reserved.l 
EndStructure 

DeviceInfoData.SP_DEVINFO_DATA 

DeviceInfoData\cbSize=SizeOf(DeviceInfoData) 

i=0
OpenLibrary(1,"cfgmgr32.dll") 
*F1 = IsFunction(1, "CM_Get_Device_IDA") 
Repeat
If SetupDiEnumDeviceInfo_(hDeviceInfoSet,i,@DeviceInfoData) = 0
Break
EndIf
i+1
pnplen = 255
pnp.s = Space(bufferlen)
CallFunctionFast(*F1,DeviceInfoData\DevInst,@pnp,pnplen,0) 
Debug pnp
ForEver
CloseLibrary(1)

SetupDiDestroyDeviceInfoList_(hDeviceInfoSet)
im prinzip all das , was unter HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum aktiv ist .

Verfasst: 29.01.2005 20:18
von Hroudtwolf
Kann man nur sagen ...Klasse ! :allright:

Re: alle hardware-PNPs des systems ermitteln

Verfasst: 19.05.2011 10:11
von Oliver13
Hallo zusammen,

der obige Code funktioniert super. Nun wollte ich diesen erweitern, um auch die Beschreibung bzw. weitere Infos (FriendlyName) über den ermittelten PNP-Schlüssel aus der Registry zu holen - das führt dann aber regelmäßig zum Absturz, wenn ein Schlüssel nicht existiert.

Es muß mit dem Code zum ermitteln der PNP zusammenhängen, denn die Registryroutine funktioniert ansonsten problemlos.

Code: Alles auswählen

; Registry code: Stephen Rodriguez, 
; Based upon code found at : http://www.purebasic.fr/german/viewtopic.php?p=177460#177460
; and http://forums.purebasic.com/german/viewtopic.php?f=8&t=1833

Procedure.s RegGetValue(topKey, sKeyName.s, sValueName.s, ComputerName.s = "")
  Protected lpData.s=Space(255), GetValue.s
  Protected GetHandle.l, hKey.l, lReturnCode.l, lhRemoteRegistry.l, lpcbData.l, lType.l, lpType.l
  Protected lpDataDWORD.l

  If Left(sKeyName, 1) = "\"
    sKeyName = Right(sKeyName, Len(sKeyName) - 1)
  EndIf

  If ComputerName = ""
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_READ, @hKey)
  Else
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_READ, @hKey)
  EndIf

  If GetHandle = #ERROR_SUCCESS
    lpcbData = 255
   
    GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)

    If GetHandle = #ERROR_SUCCESS
      Select lType
        Case #REG_SZ
          GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)

          If GetHandle = 0
            GetValue = Left(lpData, lpcbData - 1)
          Else
            GetValue = ""
          EndIf

        Case #REG_DWORD
          GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lpType, @lpDataDWORD, @lpcbData)

          If GetHandle = 0
            GetValue = Str(lpDataDWORD)
          Else
            GetValue = "0"
          EndIf
        Case #REG_BINARY
           
          *bdat=AllocateMemory(lpcbdata)           
          GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lpType, *bdat, @lpcbData)
          If GetHandle = 0
            While a = < lpcbData -1
              GetValue + RSet(Hex(PeekB(*bdat+a) & $FF,1),2,"0")
              a+1
            Wend
          Else
            GetValue = ""
          EndIf
          FreeMemory(*bdat)
      EndSelect
    EndIf
  EndIf
  RegCloseKey_(hKey)
  ProcedureReturn GetValue
EndProcedure


Structure SP_DEVINFO_DATA 
  cbSize.l 
  ClassGuid.GUID 
  DevInst.l 
  Reserved.l 
EndStructure 


Procedure GetHardware()
#DIGCF_PRESENT                     =   2 
#DIGCF_ALLCLASSES                  =   4 
Protected shwd$
Protected g$,ab$,ab1$
Protected g1$,i,sg$

hDeviceInfoSet = SetupDiGetClassDevs_(0,0,0,#DIGCF_PRESENT|#DIGCF_ALLCLASSES) 


DeviceInfoData.SP_DEVINFO_DATA 

DeviceInfoData\cbSize=SizeOf(DeviceInfoData) 

i=0 
OpenLibrary(1,"cfgmgr32.dll") 
*F1 = GetFunction(1, "CM_Get_Device_IDA") 
Repeat 

If SetupDiEnumDeviceInfo_(hDeviceInfoSet,i,@DeviceInfoData) <> 0 

i+1 
pnplen = 256
pnp.s = Space(bufferlen) 
;CallFunction(1,"CM_Get_Device_IDA",DeviceInfoData\DevInst,@pnp,pnplen,0) 

CallFunctionFast(*F1,DeviceInfoData\DevInst,@pnp,pnplen,0) 
shwd$+Trim(pnp)+Chr(13)

Else
  Break 
EndIf 

ForEver 
CloseLibrary(1) 

SetupDiDestroyDeviceInfoList_(hDeviceInfoSet) 

gf=CountString(shwd$,Chr(13))-1
For i=1 To gf
g$= StringField(shwd$,i,Chr(13))
sg$="SYSTEM\CurrentControlSet\Enum\"+g$+"\"
ab$=RegGetValue(#HKEY_LOCAL_MACHINE,sg$,"DeviceDesc")

ab1$=RegGetValue(#HKEY_LOCAL_MACHINE,sg$,"Mfg")
If ab1$=""
ab1$=RegGetValue(#HKEY_LOCAL_MACHINE,sg$,"FriendlyName")
EndIf

Debug g$+ " ("+Trim(ab$+" "+ab1$)+")"
Next

EndProcedure


GetHardware()
Hat da jemand vielleicht eine Idee, woran das liegen könnte ?

Danke + viele Grüsse
Oli

Re: alle hardware-PNPs des systems ermitteln

Verfasst: 19.05.2011 14:57
von Bisonte

Code: Alles auswählen

pnp.s = Space(bufferlen)
zu

Code: Alles auswählen

pnp.s = Space(pnplen)
Dann rauscht es weiter.
Eine zeile drüber haste es ja schon definiert.... nur zum einsatz kam es nicht...

Edit:
Oh grad gesehen, im englischen Forum kam mir einer zuvor ;)

Re: alle hardware-PNPs des systems ermitteln

Verfasst: 19.05.2011 16:57
von tft
Hallo,

bei mir funktioniert der Code nicht. Es kommt immer "IsFunktion" is not a funktion or Variable. Ich benutze die Standart PB 4.6 Installation.

Gruss TFT

Edit: na ja ... nach etwas suchen ........ bei 4.6 muss man GetFunktion() benutzen. Funktioniert super.....

Re: alle hardware-PNPs des systems ermitteln

Verfasst: 19.05.2011 17:00
von RSBasic
IsFunction() > GetFunction():

Code: Alles auswählen

#DIGCF_PRESENT                     =   2
#DIGCF_ALLCLASSES                  =   4

hDeviceInfoSet = SetupDiGetClassDevs_(0,0,0,#DIGCF_PRESENT|#DIGCF_ALLCLASSES)

Structure SP_DEVINFO_DATA
  cbSize.l
  ClassGuid.GUID
  DevInst.l
  Reserved.l
EndStructure

DeviceInfoData.SP_DEVINFO_DATA

DeviceInfoData\cbSize=SizeOf(DeviceInfoData)

i=0
OpenLibrary(1,"cfgmgr32.dll")
*F1 = GetFunction(1, "CM_Get_Device_IDA")
Repeat
If SetupDiEnumDeviceInfo_(hDeviceInfoSet,i,@DeviceInfoData) = 0
Break
EndIf
i+1
pnplen = 255
pnp.s = Space(bufferlen)
CallFunctionFast(*F1,DeviceInfoData\DevInst,@pnp,pnplen,0)
Debug pnp
ForEver
CloseLibrary(1)

SetupDiDestroyDeviceInfoList_(hDeviceInfoSet)

Re: alle hardware-PNPs des systems ermitteln

Verfasst: 19.05.2011 17:09
von tft
Hallo Oliver13

dein Code geht bei mir nicht weil dort eine Zeile nicht stimmt..... was ist das ? "shwd$+Trim(pnp)+Chr(13)" in Zeile 101

Re: alle hardware-PNPs des systems ermitteln

Verfasst: 19.05.2011 17:14
von RSBasic
bufferlen wurde nicht mit einer Länge definiert!