1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| Option Explicit
' Cette partie du script provient de chez www.robvanderwoude.com
'Elle liste les objets COM et ActiveX présent sur windows
Const HKEY_CLASSES_ROOT = &H80000000
Dim arrProgID, lstProgID, objReg, strMsg, strProgID, strSubKey, subKey, subKeys()
Set lstProgID = CreateObject( "System.Collections.ArrayList" )
Set objReg = GetObject( "winmgmts://./root/default:StdRegProv" )
' List all subkeys of HKEY_CLASSES_ROOT\CLSID
objReg.EnumKey HKEY_CLASSES_ROOT, "CLSID", subKeys
' Loop through the list of subkeys
For Each subKey In subKeys
' Check each subkey for the existence of a ProgID
strSubKey = "CLSID\" & subKey & "\ProgID"
objReg.GetStringValue HKEY_CLASSES_ROOT, strSubKey, "", strProgID
' If a ProgID exists, add it to the list
If Not IsNull( strProgID ) Then lstProgID.Add strProgID
Next
' Sort the list of ProgIDs
lstProgID.Sort
' Copy the list to an array (this makes displaying it much easier)
arrProgID = lstProgID.ToArray
' Display the entire array
'WScript.Echo Join( arrProgID, vbCrLf )
'Boucle d'affichage de la liste d'objet
' Principe :
' Pour savoir si un objet possède une inteface scriptable, on l'instancie
' si une erreur est reportée, l'objet n'est pas scriptable
WScript.Echo "Liste des objets COM/ActiveX disponible sur votre système" & vbCrLf
Dim alpha, objet, script, resultat, shell, regex, resultatregex
Set shell = WScript.CreateObject("wscript.shell")
Set regex = New RegExp : regex.IgnoreCase= True : regex.Global= False : regex.Pattern = "[^.]+[.][^.]+"
For Each objet In arrProgID
Set resultatregex = regex.Execute (objet)
If objet <> "" And resultatregex.Count <>0 Then
' Certain objet on des guillemets, ce qui est gênant pour nous
' La plupart des objets on des chiffres la lfin du type word.document.12
' Nous ne voulons qu'une forme du type xxxx.xxxx, d'ou l'emploie d'une regex
objet = resultatregex(0).Value
objet = Replace(objet,"""","")
'Certain test d'objet plante WSH, on est obligé de runner chaque test dans un sous shell en bidouillant un peu
'(Mais la bidouille, n'es ce pas l'essence même du script ... ;)
script = "cmd /c echo Dim objet: Set objet = wscript.createobject(""" & objet & """) : WScript.Quit 33 >c:\temp.vbs "
shell.Run script,0
resultat = shell.Run ("cscript.exe c:\temp.vbs",0,true)
shell.Run "cmd /c del c:\temp.vbs",0
' à priori l'instruction run renvoie 0 même si l'instanciation s'est mal passée.
' Du coup je génère un exit code 33 à la fin pour être sur que le code est allez jusqu'au bout
If Eval(resultat = 33) Then
WScript.Echo objet
shell.Run "cmd /c echo " & objet & " >> liste.txt",0
Else
' Pour Debug only
'WScript.Echo "Exit code : " & resultat & " : " & objet & " : NOK!"
End If
Else
' Pour Debug only
'WScript.Echo "Object non traité : " & objet
End If
Next |
Partager