Aperçu des fonctionnalités de la console WSH Shell Assistance WMI à l'aide du module _wshWmi.inc Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.
_ _ _ ___ _ _ ___ _ _ _
| | | |/ __>| | | / __>| |_ ___ | || |
| | | |\__ \| | \__ \| . |/ ._>| || |
|__/_/ <___/|_|_| <___/|_|_|\___.|_||_|
Windows Script Host (WSH) Shell v1.0.0.5 starting ...
Registering components ...
Loading external modules ...
Loading _wshAdsi.inc ...
Loading _wshIni.inc ...
Loading _wshWmi.inc ...
Welcome ...
It's 03/10/2007 16:37:51 and WSH Shell is up !
Ready.
WSH D:\Test> ' utilisation du module externe _wshWmi.inc
WSH D:\Test> ' tous les modules (classes) sont chargés au démarrage de la
WSH D:\Test> ' console donc il ne reste plus qu'à créer une instance
WSH D:\Test> Set oWmi=New wshWmi
WSH D:\Test> ' détermination des membres (méthodes et propriétés)
WSH D:\Test> gm(oWmi)
Category Name
-------- ----
Function GetClasses ()
Function GetCollection (strClass)
Function GetInstance (strObjectPath)
Function GetInstances (strClass)
Function GetProperties (Object)
Property strComputer
Property strNamespace
Property Version
WSH D:\Test> ' affichage des disques logiques de la machine locale
WSH D:\Test> echo $(oWmi.GetInstances("Win32_LogicalDisk"))
Win32_LogicalDisk.DeviceID='C:'
Win32_LogicalDisk.DeviceID='D:'
Win32_LogicalDisk.DeviceID='E:'
Win32_LogicalDisk.DeviceID='F:'
WSH D:\Test> ' affichage des propriétés du disque F:
WSH D:\Test> set oDisk=oWmi.GetInstance("Win32_LogicalDisk.DeviceID='F:'")
WSH D:\Test> ft oWmi.GetProperties(oDisk),"","Value <> ''","*"
Property Value
-------- -----
Caption F:
Compressed Faux
CreationClassName Win32_LogicalDisk
Description Disque fixe local
DeviceID F:
DriveType 3
FileSystem NTFS
FreeSpace 74153005056
MaximumComponentLength 255
MediaType 12
Name F:
Size 80023715840
SupportsDiskQuotas Vrai
SupportsFileBasedCompression Vrai
SystemCreationClassName Win32_ComputerSystem
SystemName FRSOB001127
VolumeName Backup
VolumeSerialNumber B8FD59B1
WSH D:\Test> ' il est également possible d'afficher les propriétés de tous les
WSH D:\Test> ' disque de la machine locale
WSH D:\Test> Set colDisks=oWmi.GetCollection("Win32_LogicalDisk")
WSH D:\Test> ft oWmi.GetProperties(colDisks),"","","*"
Access Availability BlockSize Caption Compressed ConfigManagerErrorCode ...
------ ------------ --------- ------- ---------- ---------------------- ...
C: Faux ...
D: Faux ...
E: ...
F: Faux ...
WSH D:\Test> ' affichage de quelques propriétés uniquement
WSH D:\Test> ft oWmi.GetProperties(colDisks),"","","Caption|FileSystem|^Size$"
Caption FileSystem Size
------- ---------- ----
C: NTFS 20974428160
D: NTFS 39028953088
E:
F: NTFS 80023715840
WSH D:\Test> ' détermination des propriétés et méthodes de l'objet disque
WSH D:\Test> gm(oDisk)
Category Name
-------- ----
Method Chkdsk ()
Method ExcludeFromAutochk ()
Method Reset ()
Method ScheduleAutoChk ()
Method SetPowerState ()
Property Access
Property Availability
Property BlockSize
Property Caption
Property Compressed
Property ConfigManagerErrorCode
Property ConfigManagerUserConfig
Property CreationClassName
Property Description
Property DeviceID [*key*]
Property DriveType
Property ErrorCleared
Property ErrorDescription
Property ErrorMethodology
Property FileSystem
Property FreeSpace
Property InstallDate
Property LastErrorCode
Property MaximumComponentLength
Property MediaType
Property Name
Property NumberOfBlocks
Property PNPDeviceID
Property PowerManagementCapabilities
Property PowerManagementSupported
Property ProviderName
Property Purpose
Property QuotasDisabled
Property QuotasIncomplete
Property QuotasRebuilding
Property Size
Property Status
Property StatusInfo
Property SupportsDiskQuotas
Property SupportsFileBasedCompression
Property SystemCreationClassName
Property SystemName
Property VolumeDirty
Property VolumeName
Property VolumeSerialNumber
WSH D:\Test> ' un autre exemple
WSH D:\Test> ' détermination des produits installés sur la machine locale
WSH D:\Test> Set colProducts=oWmi.GetCollection("Win32_Product")
WSH D:\Test> ft oWmi.GetProperties(colProducts),"Name","","Name"
Name
----
Adobe Reader 7.0.5 - Français
Extension HighMAT pour l'Assistant Graver un CD de Microsoft Windows XP
Intel(R) PROSet
Microsoft .NET Framework 2.0
Microsoft Office XP Standard
QuickTime
Sonic RecordNow DX
Symantec AntiVirus
VMware Workstation
WebFldrs XP
Windows Genuine Advantage v1.3.0254.0
Windows Resource Kit Tools
Winzip 8.1 SR1 EN
WSH D:\Test> ' affichage également de la version des produits
WSH D:\Test> ' il est nécessaire de fixer la taille maximale des colonnes
WSH D:\Test> shell.nTableColumnWidth=65
WSH D:\Test> ft oWmi.GetProperties(colProducts),"Name","","Name|Version"
Name Version
---- -------
Adobe Reader 7.0.5 - Français 7.0.5
Extension HighMAT pour l'Assistant Graver un CD de Microsoft W... 1.1.1905.1
Intel(R) PROSet 6.06.2000
Microsoft .NET Framework 2.0 2.0.50727
Microsoft Office XP Standard 10.0.6626.0
QuickTime 7.0.3
Sonic RecordNow DX 4.60
Symantec AntiVirus 9.0.310
VMware Workstation 5.5.0.19175
WebFldrs XP 9.50.7523
Windows Genuine Advantage v1.3.0254.0 1.3.0254.0
Windows Resource Kit Tools 5.2.3790
Winzip 8.1 SR1 EN 1.0.0.0
WSH D:\Test> ' il est également possible de lancer cette requête sur une
WSH D:\Test> ' machine distante
WSH D:\Test> oWmi.strComputer="DEVW2K"
WSH D:\Test> Set colProducts=oWmi.GetCollection("Win32_Product")
:: An error occured (70)
:: Permission refusée
WSH D:\Test> ' Oops ! Je ne possède pas les droits nécessaires !
WSH D:\Test> ' Il est nécessaire de s'authentifier
WSH D:\Test> Set oLoc=co("WbemScripting.SWbemLocator")
WSH D:\Test> gm(oLoc)
Category Name
-------- ----
Function ConnectServer ([strServer], [strNamespace], [strUser], [strPassword...
Property Security_
WSH D:\Test> ' authentification et connexion
WSH D:\Test> Set oRWmi=oLoc.ConnectServer(oWmi.strComputer,"/root/cimv2","admini
strateur","**********")
WSH D:\Test> Set colProducts=oRWmi.InstancesOf("Win32_Product")
WSH D:\Test> ft oWmi.GetProperties(colProducts),"Name","","Name|Version"
Name Version
---- -------
ActivePerl 5.8.4 Build 810 5.8.810
ActiveState Komodo Professional 3.0.1 3.0.1
Adobe Reader 6.0.1 - Français 006.000.001
Common Setup Files (3790.0) 5.2.3790.0
Core SDK (Windows Server 2003) (3790.0) 5.2.3790.0
Java 2 Runtime Environment, SE v1.4.2_05 1.4.2_05
Java 2 SDK, SE v1.4.2_05 1.4.2_05
MySQL Administrator 1.1 1.1.6
MySQL Server 5.0 5.0.17
VMware Tools 3.1.0000
WebFldrs 9.00.3501
Windows Management Instrumentation (WMI) SDK (3790.0) 5.2.3790.0
WSH D:\Test> ' pour obtenir l'aide sur la classe wshWmi
WSH D:\Test> _gethelp * wshWmi
Name Category Synopsis
---- -------- --------
GetClasses Function Returns the complete list (array) of the classes def...
GetCollection Function Returns a collection of instances from the specified...
GetInstance Function Returns an existing instance of the specified WMI cl...
GetInstances Function Returns the instances of the specified WMI class.
GetProperties Function Returns the properties of an instancied WMI object c...
strComputer Property The netbios name or IP address of a remote computer.
strNamespace Property Specifies the WMI Namespace. Default to Root\cimv2.
Version Property Returns the class release version.
WSH D:\Test> ' Enjoy !
WSH D:\Test>
|