[EX] WMI requête matériels

Partagez vos scripts, et vos applications AutoIt.
Règles du forum
.
Répondre
Amesamana
Niveau 5
Niveau 5
Messages : 108
Enregistré le : dim. 09 sept. 2012 16:37
Status : Hors ligne

[EX] WMI requête matériels

#1

Message par Amesamana »

Bonjour,

Je construis un UDF pour des requêtes WMI. Cet UDF est personnalisé, mais il peut évoluer selon la demande, donc à modifier.
Je l'ai fait en français et en anglais.

Exemple de la première requête en français :
2016-04-23_191623.jpg
En anglais (bon sur VM :wink: )
2016-04-23_192105.jpg

Je poste cet UDF dans le but d'un exemple mais également pour vos remarques, améliorations, suggestions, en soit vos critiques positives/négatives ou et bien évidemment Constructives.

Le but étant de savoir si cela peut être intéressant de le construire en totalité... et si la méthode peut-être est la bonne.
Merci :D
WMI Hardwares.au3
(72.36 Kio) Téléchargé 394 fois
2016-04-23_192818.jpg
Classes :
Win32_OperatingSystem
Win32_BIOS
Win32_BaseBoard
Win32_Processor
PhysicalMemory
Win32_VideoController
Modifié en dernier par Amesamana le sam. 18 juin 2016 14:12, modifié 8 fois.
Avatar du membre
ricky
Niveau 7
Niveau 7
Messages : 443
Enregistré le : ven. 06 févr. 2009 09:25
Localisation : Suisse
Status : Hors ligne

Re: [EX] WMI requête matériels

#2

Message par ricky »

Hello,
pas mal, merci beaucoup. J'espère qu'il va évoluer.

J'ai une erreur en ligne 664 pour la fonction _Processor():

Code : Tout sélectionner

"D:\AutoIt\WMI Hardwares.au3" (664) : ==> The requested action with this object has failed.:
$Output &= $NbCorePermis & $objItem.NumberOfEnabledCore & @CRLF
$Output &= $NbCorePermis & $objItem^ ERROR
Si je mets la ligne en commentaire, j'ai une autre erreur en 702:

Code : Tout sélectionner

"D:\AutoIt\WMI Hardwares.au3" (702) : ==> The requested action with this object has failed.:
Local $VirtualizationFirmwareEnabled = $objItem.VirtualizationFirmwareEnabled
Local $VirtualizationFirmwareEnabled = $objItem^ ERROR
Si je mets la ligne en commentaire, j'ai une autre erreur en 714:

Code : Tout sélectionner

"D:\AutoIt\WMI Hardwares.au3" (714) : ==> The requested action with this object has failed.:
Local $VMMonitorModeExtensions = $objItem.VMMonitorModeExtensions & @CRLF
Local $VMMonitorModeExtensions = $objItem^ ERROR
Et le "& @CRLF", je crois qu'il n'a rien à faire au bout des lignes 714 et 726!

Je ne suis pas dans une machine virtuelle...
Amesamana
Niveau 5
Niveau 5
Messages : 108
Enregistré le : dim. 09 sept. 2012 16:37
Status : Hors ligne

Re: [EX] WMI requête matériels

#3

Message par Amesamana »

Merci :wink:

Est-ce ok ainsi ?
Je n'avais pas pris en compte la prise en charge de l'OS.

Code : Tout sélectionner

_Processor()


Func _WinClassesProcessor()
	$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2")
	$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", 0x10 + 0x20)
EndFunc   ;==>_WinClassesProcessor

Func _Processor()
	_WinClassesProcessor()
	If IsObj($colItems) Then
		Local $Object_Flag = 0
		For $objItem In $colItems
			$Object_Flag = 1
			$Output &= $SWMI & "Win32_Processor" & @CRLF
			$Output &= "-----------------------------------------------" & @CRLF & @CRLF
			$Output &= $NamePorcess & $objItem.Name & @CRLF
			$Output &= "Description : " & $objItem.Description & @CRLF
			$Output &= $Fabr & $objItem.Manufacturer & @CRLF
			$Output &= "Role : " & $objItem.Role & @CRLF
			$Output &= "-----------------------------------------------" & @CRLF
			$Output &= $DWitch_Process & " X " & $objItem.DataWidth & @CRLF
			$Output &= $IDProcess & $objItem.ProcessorId & @CRLF
			_TypeProc()
			$Output &= "-----------------------------------------------" & @CRLF
			$Output &= $NbCoreProcess & $objItem.NumberOfCores & @CRLF
			If @OSVersion = "WIN_10" Then ; This property is not supported before Windows Server 2016 Technical Preview and Windows 10.
				$Output &= $NbCorePermis & $objItem.NumberOfEnabledCore & @CRLF
			Else
				$Output &= $NbCorePermis & "? OSVersion < Win 10" & @CRLF
			EndIf
			$Output &= $NbCoreLogique & $objItem.NumberOfLogicalProcessors & @CRLF
			$Output &= "-----------------------------------------------" & @CRLF
			_VirtualFirWareProc()
			_VMVirtualProcess()
			_StatuInfoProc()
			$Output &= $Statut & $objItem.Status & @CRLF
			If $Object_Flag = 0 Then $Output &= $SortieWMIRF & $OutputTitle & @CRLF
			If $Output = "" Then $Output &= $SortieWMIRF_Proc & @CRLF
			If MsgBox(64, "", $Output) = 2 Then ExitLoop
		Next
	EndIf
EndFunc   ;==>_Processor

Func _TypeProc()
	_WinClassesProcessor()
	For $objItem In $colItems
		Local $ProcessorType = $objItem.ProcessorType
		Switch $ProcessorType
			Case 1
				$Output &= $TypeProcess & $OutputProc_1 & @CRLF
			Case 2
				$Output &= $TypeProcess & $OutputProc_2 & @CRLF
			Case 3
				$Output &= $TypeProcess & $OutputProc_3 & @CRLF
			Case 4
				$Output &= $TypeProcess & $OutputProc_4 & @CRLF
			Case 5
				$Output &= $TypeProcess & $OutputProc_5 & @CRLF
			Case 6
				$Output &= $TypeProcess & $OutputProc_6 & @CRLF
		EndSwitch
	Next
EndFunc   ;==>_TypeProc

Func _VirtualFirWareProc() ; ;~ Windows Server 2008 R2, Windows 7, Windows Server 2008, and Windows Vista:  This property is not supported before Windows 8 and Windows Server 2012.
	_WinClassesProcessor()
	For $objItem In $colItems
		Switch @OSVersion
			Case "WIN_10", "WIN_8.1", "WIN_8", "Win_2008", "WIN_2008R2"
				Local $VirtualizationFirmwareEnabled = $objItem.VirtualizationFirmwareEnabled
				If $VirtualizationFirmwareEnabled = True Then
					$Output &= $ProcVirtuel & @CRLF
				Else
					$Output &= $ProcVirtuelNot & @CRLF
				EndIf
			Case Else
				$Output &= $ProcVirtuelNot & @CRLF
		EndSwitch
	Next
EndFunc   ;==>_VirtualFirWareProc

Func _VMVirtualProcess() ; Windows Server 2008 R2, Windows 7, Windows Server 2008, and Windows Vista:  This property is not supported before Windows 8 and Windows Server 2012.
	_WinClassesProcessor()
	For $objItem In $colItems
		Switch @OSVersion
			Case "WIN_10", "WIN_8.1", "WIN_8", "Win_2008", "WIN_2008R2"
				Local $VMMonitorModeExtensions = $objItem.VMMonitorModeExtensions
				If $VMMonitorModeExtensions = 1 Then
					$Output &= $WMProcess & @CRLF & $WMProcessInfo & @CRLF
				Else
					$Output &= $WMProcess & @CRLF & $WMProcessInfo & @CRLF
				EndIf
			Case Else
				$Output &= $ProcVirtuelNot & @CRLF
		EndSwitch
	Next
EndFunc   ;==>_VMVirtualProcess

Func _StatuInfoProc()
	_WinClassesProcessor()
	For $objItem In $colItems
		Local $StatusInfo = $objItem.StatusInfo
		Switch $StatusInfo
			Case 1
				$Output &= $Autres & @CRLF
			Case 2
				$Output &= $Inconnu & @CRLF
			Case 3
				$Output &= $Enabled & @CRLF
			Case 4
				$Output &= $Disabled & @CRLF
			Case 5
				$Output &= $Sansobjet & @CRLF
		EndSwitch
	Next
EndFunc   ;==>_StatuInfoProc
;==>WinClassesBaseBoard
Modifié en dernier par Amesamana le dim. 01 mai 2016 17:47, modifié 3 fois.
Avatar du membre
ricky
Niveau 7
Niveau 7
Messages : 443
Enregistré le : ven. 06 févr. 2009 09:25
Localisation : Suisse
Status : Hors ligne

Re: [EX] WMI requête matériels

#4

Message par ricky »

Ça marche mieux, au moins il n'y a plus d'erreur. Enfin, pour l'instant je l'ai testé que sur windows 7. Tu parles de Windows server 2012, mais tu n'en tiens pas compte dans ton switch! Si jamais, je pourrai le tester sur toutes les platformes...

Je rappelle juste, que tu n'as pas corrigé les "& @CRLF" qui sont en trop et qui risquent de faire rater tes "if".
Amesamana
Niveau 5
Niveau 5
Messages : 108
Enregistré le : dim. 09 sept. 2012 16:37
Status : Hors ligne

Re: [EX] WMI requête matériels

#5

Message par Amesamana »

Bonjour

Merci ricky.

Corrigé dans le premier post et celui ci-dessus.
Pour Windows server 2008 je dois inclure "Win_2008" mais pour Windows Server 2008 R2, sais-tu ?
Avatar du membre
orax
Modérateur
Modérateur
Messages : 1479
Enregistré le : lun. 23 mars 2009 04:50
Localisation : ::1
Status : Hors ligne

Re: [EX] WMI requête matériels

#6

Message par orax »

C'est marqué dans la doc.
@OSVersion Returns one of the following: "WIN_10", "WIN_81", "WIN_8", "WIN_7", "WIN_VISTA", "WIN_XP", "WIN_XPe",
for Windows servers: "WIN_2016", "WIN_2012R2", "WIN_2012", "WIN_2008R2", "WIN_2008", "WIN_2003"".
De petits détails peuvent faire toute la différence. — Quand la boule de neige commence à rouler… poussez-la. (Columbo)
Amesamana
Niveau 5
Niveau 5
Messages : 108
Enregistré le : dim. 09 sept. 2012 16:37
Status : Hors ligne

Re: [EX] WMI requête matériels

#7

Message par Amesamana »

Merci Orax :)
Amesamana
Niveau 5
Niveau 5
Messages : 108
Enregistré le : dim. 09 sept. 2012 16:37
Status : Hors ligne

Re: [EX] WMI requête matériels

#8

Message par Amesamana »

Bonjour

Mise à jour de l'UDF

Ajout des fonctions suivantes :

_OperatingSystem()
_PhysicalMemory()
_VideoController()
Répondre