Freitag, 8. Oktober 2010

Informationen über den Arbeitsspeicher ermitteln / Retrieving RAM infos

Im UT kam vor ein paar Tagen die Frage auf, wie denn unter VFP Informationen über den installierten Arbeitsspeicher in Erfahrung gebracht werden könnten. Hugo Ranea lieferte daraufhin einen kurzen Mustercode zur Abfrage dieser Informationen über die Windows Management Instrumentation (WMI). Der folgende Beispielcode basiert auf seinem Codemuster.

Auf MSDN gibt es wie immer eine detaillierte Beschreibung der Funktion, die ich als Basis für die Aufschlüsselung der gelieferten Integerwerte genutzt habe.

http://msdn.microsoft.com/en-us/library/aa394347%28VS.85%29.aspx

Das u.a. Beispiel wurde von mir (in Ermangelung einer neueren Version) unter WinXP SP3 getestet.

LOCAL    loRAMs as Object, ;
        loRAM as Object, ;
        loWMI as Object, ;
        loLocator as Object

CLEAR 
loLocator    = CREATEOBJECT( [WBEMScripting.SWBEMLocator] )
loWMI        = loLocator.ConnectServer()
loRAMs        = loWMI.ExecQuery( [Select * from Win32_PhysicalMemory] )

    ? [Anzahl RAM Bausteine  : ] + TRANSFORM( loRAMs.Count )
FOR EACH loRAM IN loRAMs
    ? [----------------------- ]
    ? [Position              : ] + loRAM.DeviceLocator
    ? [Typisierung           : ] + loRAM.BankLabel
    ? [Kapazität             : ] + TRANSFORM( loRAM.Capacity )
    ? [Beschriftung          : ] + loRAM.Caption
    ? [Bandbreite            : ] + TRANSFORM( loRAM.DataWidth )
    ? [Beschreibung          : ] + loRAM.Description
    ? [Bauarttyp             : ] + GetFormFactor( loRAM.FormFactor )
    ? [HotSwap tauglich      : ] + IIF( VARTYPE( loRAM.HotSwappable )         = [X] , [nein]      , TRANSFORM( loRAM.HotSwappable ) )
    ? [Interleave Datentiefe : ] + TRANSFORM( loRAM.InterleaveDataDepth ) + IIF( loRAM.InterleaveDataDepth = 0 , [ - nicht Interleave tauglich] , [] )
    ? [Interleave Position   : ] + GetILPosition( loRAM.InterleavePosition )
    ? [Hersteller            : ] + IIF( VARTYPE( loRAM.Manufacturer )         = [X] , [unbekannt] , TRANSFORM( loRAM.Manufacturer ) )
    ? [Speichertyp           : ] + TRANSFORM( loRAM.MemoryType )
    ? [Modell                : ] + IIF( VARTYPE( loRAM.Model )                = [X] , [unbekannt] , TRANSFORM( loRAM.Model ) )
    ? [Name                  : ] + loRAM.Name
    ? [Zusätzliche Infos     : ] + IIF( VARTYPE( loRAM.OtherIdentifyingInfo ) = [X] , [keine]     , TRANSFORM( loRAM.OtherIdentifyingInfo ) )
    ? [Artikelnummer         : ] + IIF( VARTYPE( loRAM.PartNumber )           = [X] , [unbekannt] , TRANSFORM( loRAM.PartNumber ) )
    ? [Steckplatz            : ] + TRANSFORM( loRAM.PositionInRow )
    ? [PoweredOn             : ] + IIF( VARTYPE( loRAM.PoweredOn )            = [X] , [nein]      , TRANSFORM( loRAM.PoweredOn ) )
    ? [Entfernbar            : ] + IIF( VARTYPE( loRAM.PartNumber )           = [X] , [nein]      , TRANSFORM( loRAM.Removable ) )
    ? [Austauschbar          : ] + IIF( VARTYPE( loRAM.Replaceable )          = [X] , [nein]      , TRANSFORM( loRAM.Replaceable ) )
    ? [Seriennummer          : ] + IIF( VARTYPE( loRAM.SerialNumber )         = [X] , [unbekannt] , TRANSFORM( loRAM.SerialNumber ) )
    ? [Stock Keeping Unit    : ] + IIF( VARTYPE( loRAM.SKU )                  = [X] , [unbekannt] , TRANSFORM( loRAM.SKU ) )
    ? [Taktung               : ] + TRANSFORM( loRAM.Speed )
    ? [Status                : ] + IIF( VARTYPE( loRAM.Status )               = [X] , [unbekannt] , TRANSFORM( loRAM.Status ) )
    ? [Unique Identifier     : ] + TRANSFORM( loRAM.Tag )
    ? [Gesamt Bandbreite     : ] + TRANSFORM( loRAM.TotalWidth )
    ? [Typ Details           : ] + GetTypDetails( loRAM.TypeDetail )
    ? [Version               : ] + IIF( VARTYPE( loRAM.Version )              = [X] , [unbekannt] , TRANSFORM( loRAM.Version ) )
    ? [Installationsdatum    : ] + IIF( VARTYPE( loRAM.Version )              = [X] , [unbekannt] , TRANSFORM( loRAM.InstallDate ) )
ENDFOR 

FUNCTION GetFormFactor as String
LPARAMETERS vValue as Integer
    LOCAL lcReturn as String
    lcReturn = []
    vValue = EVL( vValue , 0 )
    DO CASE 
    CASE vValue = 0
        lcReturn = [0 - unbekannt]
    CASE vValue = 1
        lcReturn = [1 - anderer]
    CASE vValue = 2
        lcReturn = [2 - SIP]
    CASE vValue = 3
        lcReturn = [3 - DIP]
    CASE vValue = 4
        lcReturn = [4 - ZIP]
    CASE vValue = 5
        lcReturn = [5 - SOJ]
    CASE vValue = 6
        lcReturn = [6 - Proprietär]
    CASE vValue = 7
        lcReturn = [7 - SIMM]
    CASE vValue = 8
        lcReturn = [8 - DIMM]
    CASE vValue = 9
        lcReturn = [9 - TSOP]
    CASE vValue = 10
        lcReturn = [10 - PGA]
    CASE vValue = 11
        lcReturn = [11 - RIMM]
    CASE vValue = 12
        lcReturn = [12 - SODIMM]
    CASE vValue = 13
        lcReturn = [13 - SRIMM]
    CASE vValue = 14
        lcReturn = [14 - SMD]
    CASE vValue = 15
        lcReturn = [15 - SSMP]
    CASE vValue = 16
        lcReturn = [16 - QFP]
    CASE vValue = 17
        lcReturn = [17 - TQFP]
    CASE vValue = 18
        lcReturn = [18 - SOIC]
    CASE vValue = 19
        lcReturn = [19 - LCC]
    CASE vValue = 20
        lcReturn = [20 - PLCC]
    CASE vValue = 21
        lcReturn = [21 - BGA]
    CASE vValue = 22
        lcReturn = [22 - FPBGA]
    CASE vValue = 23
        lcReturn = [23 - LGA]
    ENDCASE 
    RETURN lcReturn
ENDFUNC 

FUNCTION GetILPosition as String
LPARAMETERS vValue as Integer
    LOCAL lcReturn as String
    lcReturn = []
    vValue = EVL( vValue , 0 )
    DO CASE 
    CASE vValue = 0
        lcReturn = [0 - Non-Interleaved]
    CASE vValue = 1
        lcReturn = [1 - Erste Position]
    CASE vValue = 2
        lcReturn = [2 - Zweite Position]
    ENDCASE 
    RETURN lcReturn
ENDFUNC 

FUNCTION GetMemoryTyp as String
LPARAMETERS vValue as Integer
    LOCAL lcReturn as String
    lcReturn = []
    vValue = EVL( vValue , 0 )
    DO CASE
    CASE vValue = 0
        lcReturn = [0 - unbekannt]
    CASE vValue = 1
        lcReturn = [1 - anderer]
    CASE vValue = 2
        lcReturn = [2 - DRAM]
    CASE vValue = 3
        lcReturn = [3 - Synchroner DRAM]
    CASE vValue = 4
        lcReturn = [4 - Cache DRAM]
    CASE vValue = 5
        lcReturn = [5 - EDO]
    CASE vValue = 6
        lcReturn = [6 - EDRAM]
    CASE vValue = 7
        lcReturn = [7 - VRAM]
    CASE vValue = 8
        lcReturn = [8 - SRAM]
    CASE vValue = 9
        lcReturn = [9 - RAM]
    CASE vValue = 10
        lcReturn = [10 - ROM]
    CASE vValue = 11
        lcReturn = [11 - Flash]
    CASE vValue = 12
        lcReturn = [12 - EEPROM]
    CASE vValue = 13
        lcReturn = [13 - FEPROM]
    CASE vValue = 14
        lcReturn = [14 - EPROM]
    CASE vValue = 15
        lcReturn = [15 - CDRAM]
    CASE vValue = 16
        lcReturn = [16 - 3DRAM]
    CASE vValue = 17
        lcReturn = [17 - SDRAM]
    CASE vValue = 18
        lcReturn = [18 - SGRAM]
    CASE vValue = 19
        lcReturn = [19 - RDRAM]
    CASE vValue = 20
        lcReturn = [20 - DDR]
    CASE vValue = 21
        lcReturn = [21 - DDR-2]
    CASE vValue = 22
        lcReturn = [22 - DDR-3]
    ENDCASE
    RETURN lcReturn
ENDFUNC 

FUNCTION GetTypDetails as String
LPARAMETERS vValue as Integer
    LOCAL lcReturn as String
    lcReturn = []
    vValue = EVL( vValue , 4 )
    DO CASE
    CASE vValue = 1
        lcReturn = [1 - reserviert]
    CASE vValue = 2
        lcReturn = [2 - anderer]
    CASE vValue = 4
        lcReturn = [4 - unbekannt]
    CASE vValue = 8
        lcReturn = [8 - Fast-paged]
    CASE vValue = 16
        lcReturn = [16 - Statische Spalten]
    CASE vValue = 32
        lcReturn = [32 - Pseudo-statisch]
    CASE vValue = 64
        lcReturn = [64 - RAMBUS]
    CASE vValue = 128
        lcReturn = [128 - Synchron]
    CASE vValue = 256
        lcReturn = [256 - CMOS]
    CASE vValue = 512
        lcReturn = [512 - EDO]
    CASE vValue = 1024
        lcReturn = [1024 - Window DRAM]
    CASE vValue = 2048
        lcReturn = [2048 - Cache DRAM]
    CASE vValue = 4096
        lcReturn = [4096 - nicht flüchtig]
    ENDCASE
    RETURN lcReturn
ENDFUNC