WSH Shell : Afficher les URL |
Écrit par Gilles LAURENT | |||
10-04-2008 | |||
WSH Shell : Afficher les URL des instances Internet Explorer en cours d'exécution Une question d'un usager sur le forum Scripting (Fr) était de savoir comment récupérer par script les URL des instances Internet Explorer en cours d'exécution. Vous pouvez retrouver ce fil ici : Je me suis amusé à réaliser cet exercice en VBScript en m'appuyant sur la console WSH Shell. J'ai finalement abouti à la solution proposée ci-dessous qui se compose :
Note : Dans le cadre de ce projet, le composant COM est utilisé pour invoquer les API Win32 suivantes :
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.8 starting ... Registering components ... Registering dyncall.dll ... Loading external modules ... Loading _wshAdsi.inc ... Loading _wshIExplore.inc ... Loading _wshIni.inc ... Loading _wshTaskView.inc ... Loading _wshWmi.inc ... Loading profiles ... Loading H:\Home\WSH\WSHShell_Profile.inc ... Welcome ... It's 10/04/2008 14:46:58 and WSH Shell is up ! Ready. WSH D:\Test> ' le composant COM externe dyncall a été enregistré de manière WSH D:\Test> ' automatique lors du démarrage de la console (cela nécessite que WSH D:\Test> ' la console soit démarrée avec les droits appropriés) WSH D:\Test> ' notre nouveau module est bien présent dans la liste des modules WSH D:\Test> ' automatiquement chargés. Il ne reste plus qu'à créer une WSH D:\Test> ' instance pour en bénéficier WSH D:\Test> Set oIE=New wshIExplore WSH D:\Test> ' détermination des membres (méthodes et propriétés) WSH D:\Test> gm(oIE) Category Name -------- ---- Function GetIERunningInstances () Property InstanceCount Property Version WSH D:\Test> ' combien d'instances IE sont actuellement en cours d'exécution ? WSH D:\Test> echo oIE.InstanceCount 11 WSH D:\Test> ' affichage formaté des instances IE en cours (id, nom et URL) WSH D:\Test> ft oIE.GetIERunningInstances(),"Id","","*" Id Name URL -- ---- --- 504 IEXPLORE.EXE http://www.suez.com/fr/suez/ 1064 IEXPLORE.EXE http://www.microsoft.com/communities/newsgroups/en-us/def... 1064 IEXPLORE.EXE http://glsft.free.fr/index.php?option=com_content&task=vi... 1064 IEXPLORE.EXE http://glsft.free.fr/administrator/index.php?mosmsg=Sessi... 1064 IEXPLORE.EXE http://www.google.fr/search?hl=fr&q=axiome+chanteloup&met... 1064 IEXPLORE.EXE http://www.google.fr/ 1064 IEXPLORE.EXE http://www.google.fr/ 1064 IEXPLORE.EXE http://www.google.fr/search?hl=fr&q=html+table+scroll&met... 1064 IEXPLORE.EXE http://msdn2.microsoft.com/en-us/library/aa390351(VS.85).... 1064 IEXPLORE.EXE http://www.google.fr/search?hl=fr&q=microsoft+moss&meta= 1304 explorer.exe file:///D:/ WSH D:\Test> ' NOTE: on remarque que plusieurs instances d'Internet Explorer WSH D:\Test> ' sont affichées ici avec deux Id distincts (504) et (1064) WSH D:\Test> ' - le premier processus (504) gère une seule instance de fenêtre WSH D:\Test> ' - le second processus (1064) gère neuf instances de fenêtre WSH D:\Test> ' NOTE: une instance de l'explorateur de fichiers est également WSH D:\Test> ' affichée ici avec l'Id (1304) WSH D:\Test> WSH D:\Test> ' démarrage d'une nouvelle instance d'Internet Explorer WSH D:\Test> Set oIEInst=co("InternetExplorer.Application") WSH D:\Test> oIEInst.Navigate("http://www.yahoo.fr") WSH D:\Test> oIEInst.Visible=True WSH D:\Test> WSH D:\Test> ' affichage formaté des instances IE en cours (id, nom et URL) WSH D:\Test> ft oIE.GetIERunningInstances(),"Id","Name Like 'IE*'","*" Id Name URL -- ---- --- 504 IEXPLORE.EXE http://www.suez.com/fr/suez/ 1064 IEXPLORE.EXE http://www.microsoft.com/communities/newsgroups/en-us/def... 1064 IEXPLORE.EXE http://glsft.free.fr/index.php?option=com_content&task=vi... 1064 IEXPLORE.EXE http://glsft.free.fr/administrator/index.php?mosmsg=Sessi... 1064 IEXPLORE.EXE http://www.google.fr/search?hl=fr&q=axiome+chanteloup&met... 1064 IEXPLORE.EXE http://www.google.fr/ 1064 IEXPLORE.EXE http://www.google.fr/ 1064 IEXPLORE.EXE http://www.google.fr/search?hl=fr&q=html+table+scroll&met... 1064 IEXPLORE.EXE http://msdn2.microsoft.com/en-us/library/aa390351(VS.85).... 1064 IEXPLORE.EXE http://www.google.fr/search?hl=fr&q=microsoft+moss&meta= 1064 IEXPLORE.EXE http://fr.yahoo.com/ WSH D:\Test> ' la nouvelle instance de fenêtre apparaît bien dans la liste WSH D:\Test> ' maintenant démarrage d'un nouveau processus Internet Explorer WSH D:\Test> ' de manière interactive WSH D:\Test> ' la nouvelle instance pointe sur le site web Mappy WSH D:\Test> WSH D:\Test> ' affichage formaté des instances IE en cours (id, nom et URL) WSH D:\Test> ft oIE.GetIERunningInstances(),"Id","URL Like '%mappy%'","*" Id Name URL -- ---- --- 1708 IEXPLORE.EXE http://www.mappy.fr WSH D:\Test> ' la nouvelle instance d'Internet Explorer possède le pid (1708) WSH D:\Test> ' Enjoy ! WSH D:\Test> Listing 1 : _wshIExplore.inc
|
|||
Dernière mise à jour : ( 10-04-2008 ) |