ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Informations sur la machine   



L'auteur

FoxInCloud (Th. Nivelet)
France France
Membre Simple
# 0000000014
enregistré le 13/10/2004

http://www.foxincloud.com/
Nivelet Thierry
75016 Paris
de la société Abaque
Fiche personnelle


Note des membres
pas de note

Contributions > 05 - API et appels systèmes

Informations sur la machine
# 0000000219
ajouté le 07/07/2005 10:08:49 et modifié le 04/06/2007
consulté 9850 fois
Niveau initié

Version(s) Foxpro :
VFP 9.0
VFP 8.0
VFP 7.0
VFP 6.0
VFP 5.0
VFP 3.0

Description

Classe exposant les informations sur le système, le processeur et la mémoire de la machine.

Exécuter "abMachineInfo_Test" pour voir les résultats

C'est l'article Q181289 de la Base de Connaissance (KB) VFP déniché par Fred que j'ai adapté, amélioré et francisé.

Programmé en classe pour un accès et une adaptation plus faciles par nos amis foxeurs.

Peut être enrichie avec d'autres fonctions API windows intéressantes si vous en connaissez.

Code source :
  * ==================================
  DEFINE CLASS abMachineInfo as Relation && Fournit les informations sur la machine : processeur, mémoire, etc.

  * Système
  nOEMid = 0
  nPageSize = 0
  nAppAddrMin = 0
  nAppAddrMax = 0
  nProcessorMask = 0
  nProcessors = 0
  nProcessorType = 0
  cProcessorName = Space(0)
  nAllocationGranularity = 0
  nReserved = 0

  * Mémoire
  nMemLoad = 0
  nMemPhysTot = 0
  nMemPhysAvail = 0
  nPageFileTot = 0
  nPageFileAvail = 0
  nMemVirtualTot = 0
  nMemVirtualAvail = 0

  * Processeur
  nAddressWidth = 0
  nArchitecture = 0
  nAvailability = 0
  nCpuStatus = 0
  nCurrentClockSpeed = 0
  nDataWidth = 0
  cDescription = space(0)
  cDeviceID = space(0)
  nExtClock = 0
  nFamily = 0
  nL2CacheSize = 0
  nL2CacheSpeed = 0
  nLevel = 0
  nLoadPercentage = 0
  cManufacturer = space(0)
  nMaxClockSpeed = 0
  cProcessorFullName = space(0)
  cPNPDeviceID = space(0)
  cProcessorId = space(0)
  nProcessorType = 0
  nRevision = 0
  cRole = space(0)
  cSocketDesignation = space(0)
  nStatusInfo = 0
  cStepping = space(0)
  cUniqueId = space(0)
  nUpgradeMethod = 0
  cVersion = space(0)
  nVoltageCaps = 0

  * ------------------------------------
  PROCEDURE SystemInfo && Peuple les informations système

   DECLARE GetSystemInfo IN win32api STRING @lcSystemInfo
   LOCAL lcSysInfo
   m.lcSysInfo = SPACE(36)
   GetSystemInfo(@lcSysInfo)

   this.nOEMid = StrToLong(LEFT(m.lcSysInfo, 4))
   this.nPageSize = StrToLong(SUBSTR(m.lcSysInfo, 5, 4))
   this.nAppAddrMin = StrToLong(SUBSTR(m.lcSysInfo, 9, 4))
   this.nAppAddrMax = StrToLong(SUBSTR(m.lcSysInfo, 13, 4))
   this.nProcessorMask = StrToLong(SUBSTR(m.lcSysInfo, 17, 4))
   this.nProcessors = StrToLong(SUBSTR(m.lcSysInfo, 21, 4))
   this.nProcessorType = StrToLong(SUBSTR(m.lcSysInfo, 25, 4))
   this.nAllocationGranularity = StrToLong(SUBSTR(m.lcSysInfo, 29, 4))
   this.nReserved = StrToLong(SUBSTR(m.lcSysInfo, 33, 4))

   #DEFINE PROCESSOR_INTEL_386 386
   #DEFINE PROCESSOR_INTEL_486 486
   #DEFINE PROCESSOR_INTEL_PENTIUM 586
   #DEFINE PROCESSOR_MIPS_R4000 4000
   #DEFINE PROCESSOR_ALPHA_21064 21064
   DO CASE
   CASE this.nProcessorType = PROCESSOR_INTEL_386
      this.cProcessorName = "INTEL 386"
   CASE this.nProcessorType = PROCESSOR_INTEL_486
      this.cProcessorName = "INTEL 486"
   CASE this.nProcessorType = PROCESSOR_INTEL_PENTIUM
      this.cProcessorName = "INTEL Pentium"
   CASE this.nProcessorType = PROCESSOR_MIPS_R4000
      this.cProcessorName = "MIPS R4000"
   CASE this.nProcessorType = PROCESSOR_ALPHA_21064
      this.cProcessorName = "ALPHA 21064"
   ENDCASE

  * ------------------------------------
  PROCEDURE MemoryInfo && Peuple les informations mémoire

   DECLARE GlobalMemoryStatus IN win32api STRING @lcMemStat
   LOCAL lcMemStat
   m.lcMemStat = LongToStr(32) + REPLICATE(CHR(0), 28)
   GlobalMemoryStatus(@m.lcMemStat)

   this.nMemLoad = StrToLong(SUBSTR(m.lcMemStat, 5, 4))
   this.nMemPhysTot = StrToLong(SUBSTR(m.lcMemStat, 9, 4))
   this.nMemPhysAvail = StrToLong(SUBSTR(m.lcMemStat, 13, 4))
   this.nPageFileTot = StrToLong(SUBSTR(m.lcMemStat, 17, 4))
   this.nPageFileAvail = StrToLong(SUBSTR(m.lcMemStat, 21, 4))
   this.nMemVirtualTot = StrToLong(SUBSTR(m.lcMemStat, 25, 4))
   this.nMemVirtualAvail = StrToLong(SUBSTR(m.lcMemStat, 29, 4))

  * ------------------------------------
  PROCEDURE ProcessorInfo && Peuple les informations sur le processeur

  LOCAL loWMIService, loItems, loItem
  loWMIService = Getobject("winmgmts:\\.\root\cimv2")
  loItems = loWMIService.ExecQuery("Select * from Win32_Processor")

  For Each loItem In loItems
    this.nAddressWidth = loItem.AddressWidth
    this.nArchitecture = loItem.Architecture
    this.nAvailability = loItem.Availability
    this.nCpuStatus = loItem.CpuStatus
    this.nCurrentClockSpeed = loItem.CurrentClockSpeed
    this.nDataWidth = loItem.DataWidth
    this.cDescription = Alltrim(loItem.Description)
    this.cDeviceID = Alltrim(loItem.DeviceID)
    this.nExtClock = loItem.ExtClock
    this.nFamily = loItem.Family
    this.nL2CacheSize = loItem.L2CacheSize
    this.nL2CacheSpeed = loItem.L2CacheSpeed
    this.nLevel = loItem.Level
    this.nLoadPercentage = loItem.LoadPercentage
    this.cManufacturer = Alltrim(loItem.Manufacturer)
    this.nMaxClockSpeed = loItem.MaxClockSpeed
    this.cProcessorFullName = Alltrim(loItem.Name)
    this.cPNPDeviceID = loItem.PNPDeviceID
    this.cProcessorId = Alltrim(loItem.ProcessorId)
    this.nProcessorType = loItem.ProcessorType
    this.nRevision = loItem.Revision
    this.cRole = Alltrim(loItem.Role)
    this.cSocketDesignation = Alltrim(loItem.SocketDesignation)
    this.nStatusInfo = loItem.StatusInfo
    this.cStepping = Alltrim(loItem.Stepping)
    this.cUniqueId = Alltrim(loItem.UniqueId)
    this.nUpgradeMethod = loItem.UpgradeMethod
    this.cVersion = Alltrim(loItem.Version)
    this.nVoltageCaps = loItem.VoltageCaps
  Next

  ENDDEFINE && CLASS abMachineInfo

  * ==================================
  PROCEDURE abMachineInfo_Test && Teste abMachineInfo

  LOCAL lnSeconds, loMI as abMachineInfo of abDev.prg
  loMI = CreateObject('abMachineInfo')

  #DEFINE MEM_DISP_FORMAT '9 999 999 999'

  lnSeconds = Seconds()
  loMI.systemInfo()
  lnSeconds = Seconds() - m.lnSeconds
  MessageBox(;
    "Informations Système:" + CR + ;
    "- Identifiant OEM: " + Transform(m.loMI.nOEMid) + CR + ;
    "- Taille de page : " + Transform(m.loMI.nPageSize) + CR + ;
    "- Adresse application minimum : " + Transform(m.loMI.nAppAddrMin, MEM_DISP_FORMAT) + CR +;
    "- Adresse application maximum : " + Transform(m.loMI.nAppAddrMax, MEM_DISP_FORMAT) + CR + ;
    "- Masque de processeur: " + Transform(m.loMI.nProcessorMask) + CR + ;
    "- Nombre de processeurs: " + Transform(m.loMI.nProcessors) + CR + ;
    "- Nom du processeur : " + m.loMI.cProcessorName + CR + ;
    "- Granularité d'allocation (NDR?): " + Transform(m.loMI.nAllocationGranularity) + CR + ;
    + CR + "Temps d'exécution : " + Transform(m.lnSeconds) + " secondes" ;
   ,64)

  lnSeconds = Seconds()
  loMI.memoryInfo()
  lnSeconds = Seconds() - m.lnSeconds
  MessageBox(;
    "Informations Mémoire:" + CR + ;
    "- Mémoire utilisée : " + Transform(m.loMI.nMemLoad) + '%' + CR + ;
    "- Mémoire physique totale : " + Transform(m.loMI.nMemPhysTot, MEM_DISP_FORMAT) + " octets" + CR + ;
    "- Mémoire physique disponible : " + Transform(m.loMI.nMemPhysAvail, MEM_DISP_FORMAT) + " octets" + CR + ;
    "- Mémoire paginée totale : " + Transform(m.loMI.nPageFileTot, MEM_DISP_FORMAT) + " octets" + CR + ;
    "- Mémoire paginée disponible : " + Transform(m.loMI.nPageFileAvail, MEM_DISP_FORMAT) + " octets" + CR + ;
    "- Mémoire virtuelle totale : " + Transform(m.loMI.nMemVirtualTot, MEM_DISP_FORMAT) + " octets" + CR + ;
    "- Mémoire virtuelle disponible : " + Transform(m.loMI.nMemVirtualAvail, MEM_DISP_FORMAT) + " octets" + CR + ;
    + CR + "Temps d'exécution : " + Transform(m.lnSeconds) + " secondes" ;
   ,64)

  lnSeconds = Seconds()
  loMI.processorInfo()
  lnSeconds = Seconds() - m.lnSeconds
   MessageBox(;
    "- Address Width : " + Transform(m.loMI.nAddressWidth) + CR + ;
    "- Architecture : " + Transform(m.loMI.nArchitecture) + CR + ;
    "- Availability : " + Transform(m.loMI.nAvailability) + CR + ;
    "- CPU Status : " + Transform(m.loMI.nCpuStatus) + CR + ;
    "- Current Clock Speed : " + Transform(m.loMI.nCurrentClockSpeed) + CR + ;
    "- Data Width : " + Transform(m.loMI.nDataWidth) + CR + ;
    "- Description : " + Transform(m.loMI.cDescription) + CR + ;
    "- Device ID : " + Transform(m.loMI.cDeviceID) + CR + ;
    "- Ext Clock : " + Transform(m.loMI.nExtClock) + CR + ;
    "- Family : " + Transform(m.loMI.nFamily) + CR + ;
    "- L2 Cache Size : " + Transform(m.loMI.nL2CacheSize) + CR + ;
    "- L2 Cache Speed : " + Transform(m.loMI.nL2CacheSpeed) + CR + ;
    "- Level : " + Transform(m.loMI.nLevel) + CR + ;
    "- Load Percentage : " + Transform(m.loMI.nLoadPercentage) + CR + ;
    "- Manufacturer : " + Transform(m.loMI.cManufacturer) + CR + ;
    "- Maximum Clock Speed : " + Transform(m.loMI.nMaxClockSpeed) + CR + ;
    "- Processor Full Name : " + Transform(m.loMI.cProcessorFullName) + CR + ;
    "- PNP Device ID : " + Transform(m.loMI.cPNPDeviceID) + CR + ;
    "- Processor Id : " + Transform(m.loMI.cProcessorId) + CR + ;
    "- Processor Type : " + Transform(m.loMI.nProcessorType) + CR + ;
    "- Revision : " + Transform(m.loMI.nRevision) + CR + ;
    "- Role : " + Transform(m.loMI.cRole) + CR + ;
    "- Socket Designation : " + Transform(m.loMI.cSocketDesignation) + CR + ;
    "- Status Information : " + Transform(m.loMI.nStatusInfo) + CR + ;
    "- Stepping : " + Transform(m.loMI.cStepping) + CR + ;
    "- Unique Id : " + Transform(m.loMI.cUniqueId) + CR + ;
    "- Upgrade Method : " + Transform(m.loMI.nUpgradeMethod) + CR + ;
    "- Version : " + Transform(m.loMI.cVersion) + CR + ;
    "- Voltage Caps : " + Transform(m.loMI.nVoltageCaps)+ CR + ;
    + CR + "Temps d'exécution : " + Transform(m.lnSeconds) + " secondes" ;
   ,64)

  * ------------------------------------
   FUNCTION LongToStr && Représentation ASCII d'un entier 32 bits positif
   LPARAMETERS ;
      tnLongVal && Entier 32 bits positif
   LOCAL lcResult
   lcResult = Space(0)

   LOCAL i, lnLongVal
   lnLongVal = m.tnLongVal
   FOR i = 24 TO 0 STEP -8
      lcResult = Chr(Int(m.lnLongVal/(2^m.i))) + m.lcResult
      lnLongval = Mod(m.lnLongVal, (2^m.i))
   NEXT

   RETURN lcResult

  * ------------------------------------
   FUNCTION StrToLong && Entier 32 bits positif à partir de sa représentation ASCCI
   LPARAMETERS ;
     tcLongStr && Représentation ASCII d'un entier 32 bits positif
   LOCAL lnResult
   lnResult = 0

   LOCAL i, lcLongStr
   lcLongStr = m.tcLongStr
   FOR i = 0 TO 24 STEP 8
      lnResult = m.lnResult + (Asc(m.lcLongStr) * (2^m.i))
      lcLongStr = Right(m.lcLongStr, Len(m.lcLongStr) - 1)
   NEXT

   RETURN lnResult

Commentaires
le 14/02/2006, shevshenko a écrit :
Je suis débutant et je voudrais savoir comment l'utiliser.
Merci


Publicité

Les pubs en cours :


www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2024.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3