Aperçu des fonctionnalités de la console WSH Shell Intégration d'un module externe Les modules externes permettent d'ajouter de nouvelles fonctionnalités à la console WSH Shell. Ces modules sont automatiquement chargés au démarrage de la console et donc directement accessibles. Ils peuvent être développés selon deux formats distincts : - Le format "standard" représenté par des fonctions et procédures
- Le format "objet" représenté par une classe contenant des méthodes et des propriétés. Ce format est à privilégier.
Les modules externes sont stockés dans le sous-dossier \Include. Il doivent respecter la règle de nommage suivante : _wsh<Description>.inc
Les modules externes devront impérativement être accompagnés d'une documentation, même succincte, dans le but de documenter les méthodes et propriétés des classes instanciées. Les fichiers d'aide au format XML seront déposés dans le sous-dossier \Help et respecteront la règle de nommage suivante : _wsh<Description>.xml
NOTE: Le format XML des fichiers d'aide sera documenté dans un autre article. Ci-dessous un exemple de module externe développé dans le format objet. Ce module expose une seule méthode "GetScores" qui a pour but d'extraire d'une page HTML les résultats des Microsoft Scripting Games 2007. Note: Inspiré du MVP PowerShell /\/\o\/\/ http://thepowershellguy.com/blogs/posh/archive/2007/02/19/scripting-games-2007-advanced-powershell-scores-list.aspx _wshScriptingGames.inc '
' Windows Script Host (WSH) Shell
' (c) 2007 Gilles LAURENT
' wshScriptingGames Class v1.0.0.1
'
Option Explicit
Class WSHScriptingGames
' =========================
' == PRIVATE PROPERTIES
' =========================
Private oFs, oRe
' =========================
' == PUBLIC PROPERTIES
' =========================
Public Property Get Version ()
oRe.Pattern="v(\d\.\d.*)"
Version = oRe.Execute ( _ oFs.OpenTextFile ("Include\_wshScriptingGames.inc", 1, False).ReadAll ())(0).SubMatches (0)
End Property
' =========================
' == PRIVATE MEMBERS
' =========================
Private Sub Class_Initialize ()
' initialisation des objets
Set oFs = CreateObject ("Scripting.FileSystemObject")
Set oRe = New RegExp
' définition des propriétés de l'expression régulière
oRe.IgnoreCase = True
oRe.Multiline = False
oRe.Global = True
End Sub
Private Sub Class_Terminate ()
' libération des objets
Set oFs = Nothing
Set oRe = Nothing
End Sub
' =========================
' == PUBLIC MEMBERS
' =========================
Public Function GetScores (strHtmlContent)
' déclaration des variables
Dim oMatch
Dim colMatches
Dim arrLines(): ReDim arrLines(0)
Dim i, j: j=0
oRe.Pattern = "l" & Chr(34) & ">(.*?)
arrLines(0) = Replace ( _ "Name|Country|E1|E2|E3|E4|E5|E6|E7|E8|E9|E10|Total|", "|", Shell.strTableFieldSep)
Set colMatches = oRe.Execute (strHtmlContent)
For i=13 to colMatches.count-1
Set oMatch = colMatches (i)
If i Mod 13=0 Then
arrLines(j) = Left(arrLines(j), Len(arrLines(j))-1)
j=j+1
ReDim Preserve arrLines(j)
End If
arrLines(j)=arrLines(j) & oMatch.SubMatches(0) & Shell.strTableFieldSep
Next
arrLines(j) = Left(arrLines(j), Len(arrLines(j))-1)
GetScores = arrLines
End Function
End Class
Démarrage de la console WSH Shell après avoir déposé le module externe dans le sous-dossier \Include :
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 _wshScriptingGames.inc ...
Loading _wshWmi.inc ...
Welcome ...
It's 07/10/2007 18:46:11 and WSH Shell is up !
Ready.
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 oSG=New wshScriptingGames
WSH D:\Test> ' détermination des membres (méthodes et propriétés)
WSH D:\Test> gm(oSG)
Category Name
-------- ----
Function GetScores (strHtmlContent)
Property Version
WSH D:\Test> ' on retrouve bien ici notre méthode "GetScores"
WSH D:\Test> ' lecture de la page HTML des résultats VBScript Advanced
WSH D:\Test> ' cette page est disponible à l'adresse suivante :
WSH D:\Test> ' http://www.microsoft.com/technet/scriptcenter/funzone/games
WSH D:\Test> ' /games07/vbascores.mspx
WSH D:\Test> ' here we go !
WSH D:\Test> strHtmlPage=DownloadString("http://www.microsoft.com/technet" & _
>> "/scriptcenter/funzone/games/games07/vbascores.mspx", arrRetCode)
>>
WSH D:\Test> ' la variable de type tableau "arrRetCode" passée comme argument
WSH D:\Test> ' contient le code de retour de la requête HTTP
WSH D:\Test> echo $(arrRetCode)
200
OK
WSH D:\Test> ' à priori tout est en ordre :-)
WSH D:\Test> ' nous allons maintenant formater les données "brutes" avec
WSH D:\Test> ' notre méthode "GetScores"
WSH D:\Test> arrScores=oSG.GetScores(strHtmlPage)
WSH D:\Test> ' quel était le nombre de participants ?
WSH D:\Test> echo UBound(arrScores) + 0
262
WSH D:\Test> ' NOTE: (+ 0) car le tableau formaté contient également la
WSH D:\Test> ' définition des colonnes
WSH D:\Test> ' affichage sous forme de tableau des scores
WSH D:\Test> ft arrScores,"","","Name|Country|Total"
Name Country Total
---- ------- -----
Alan Dunbar Canada 100
Alan Mosley Australia 100
Alan Roberson USA 100
Alex Duckworth Australia 100
AlioTheFool USA 100
Ben Simkins Switzerland 100
Blackhawk Canada 100
Bob Stammers No Affiliation 100
Chris Bland Canada 100
Chris Osborne USA 100
Christian Pfeiffer Austria 100
Clifford Williamson, III USA 100
Clinton Huff USA 100
Courtney Newman USA 100
Craig Naumann Australia 100
Curtis J. O'Connell USA 100
Dan Richardson USA 100
Darren Malik USA 100
Dave E United Kingdom 100
Dave Rosen Israel 100
Dave Wyatt USA 100
David Coles Australia 100
Dennis G. Landsem Norway 100
djhayman Australia 100
DrBayer Vandyland 100
Ed Z USA 100
Eelco Ligtvoet The Netherlands 100
Eric Payne USA 100
Erik Renes The Netherlands 100
Fábio de Paula Junior Brazil 100
Francis de la Cerna USA 100
Frank den Haan The Netherlands 100
Frank Fattizzi USA 100
Fred Jenkins USA 100
Geoffrey Grinton Australia 100
Gilles LAURENT France 100
Gordon Yuen Bmraarykduesn 100
Gyorgy Nemesmagasi Hungary 100
H. S. Denmark 100
H2Data Australia 100
Helder Sepulveda Cuba Libre 100
Homer Yu ITExpert 100
Hong Quan YU China 100
Imran Hashim Pakistan 100
Jakub Niedzwiedz Poland 100
James Ward USA 100
Jan Kuvaja Sweden 100
Jarno Mäki Finland 100
Jason Clement USA 100
Jason Joy USA 100
Jean - JMST Belgium 100
Jerry G USA 100
Jerzy Prusinski Poland 100
John Medwid DSG 100
John Reichenbach USA 100
Josh Bradbury Kazakhstan 100
Luis Martín Caballero Spain 100
Marcus L. Farmer USA 100
Mark B USA 100
Matthew R. Davis USA 100
Matto Australia 100
Maureen Farrell USA 100
Michaela Doil Germany 100
micra Poland 100
Mike Holden Albania 100
Miles Willmek Canada 100
MrRat USA 100
Nick Ford England 100
Patrick Donahue USA 100
Patrick O'Connell USA 100
Paul M Marshall Australia 100
Peacerich Timecastle Sweden 100
Robert Moore New Zealand 100
Russ Pitcher England 100
Russell Smith USA 100
ScriptingGuys-TargetChapter Targetopia 100
Stefan Suesser Germany 100
Stephen Coombes USA 100
Steve Kulyk Canada 100
SUF Hungary 100
Tim Laqua USA 100
Tobias Reinwald Germany 100
wa ayoub No Affiliation 100
Willem van Egmond The Netherlands 100
Anoop Puthan Veetil India 95
Brad Schafbuch USA 95
Des Finkenzeller United Kingdom 95
Jens Frieben Germany 95
Natan Kahana Israel 95
Rob Shannon Australia 95
Sean Wheeler USA 95
Andre Starkloff Germany 94
Daniel Laurel USA 94
CHig USA 93
Chris Hollenbeck USA 93
Nagy János Hungary 93
Chuck Webb USA 92
Daniel Carr Canada 92
Daniel Grundel USA 92
Sidewinder Dataland 92
Brian Carr Scotland 91
Ronen Shurer Israel 91
Andy Sturycz USA 90
Drew Monrad Canada 90
Kris VG Belgium 90
Mark McGilly Ireland 90
Muhammad Faheem Sarani Pakistan 90
Pavol Popovic USA 90
Peter J Harrison United Kingdom 90
Seth Levenberg No Affiliation 90
Simon Dalling England 90
ydy Switzerland 90
Micho Janssen South Africa 89
Miguel Alvarez Spain 89
Paul Cook Australia 89
Rubens Farias Brazil 88
Shane W Australia 88
Simon Ledo USA 88
Reinhard Lehrbaum Austria 87
Shannon Turner USA 87
Abdyushev Pavel Russia 85
Chris Davidson USA 85
Chris Hanlon USA 85
DrJohnM USA 85
Greg Hovey Qatar 85
Joe Matyaz USA 85
Masami Motohashi Japan 85
Rob van der Woude The Netherlands 85
WYN Canada 85
C.M.Burnes Germany 84
Raja Mohamad Fairuz Malaysia 83
Tom Rodgers USA 83
Kasey Nichols USA 82
Maz United Kingdom 82
Roland Indra Austria 82
gamabyte USA 80
ljfong Kara-Tur 80
Robert Dunham (Nilpo) USA 80
Tim Genge United Kingdom 80
Bob Trapp USA 79
Julio Garcia United Kingdom 78
Jim Wells USA 77
pake73 Sweden 77
Arden Pineda Winterfell 76
Carl Dockum USA 75
Chris H (C2) USA 75
Greg Haak USA 75
Lance Montana Vanuatu 75
Rafael T Ryukyu 75
Ritchie Trewin Australia 75
Shay Levy Israel 75
Mrk Guatemala 74
The un1337 one Hyrule 73
Jaroslav Strunc Czech Republic 72
Andrew Chuvahin Ukraine 70
Colet Robin No Affiliation 70
EvEm_Relic Australia 70
Mike Marr Canada 70
Peter Sarf Slovenia 70
Richard Horne USA 70
Stef R No Affiliation 70
Tracy Cook USA 70
Vinod Dadhe India 70
Jonas Nywall Sweden 68
Darren Palmer USA 67
Chris Swinford, Idea Integration USA 65
Daniel Gooderidge Australia 65
Kevin Thompson Canada 65
TLH USA 65
Karl Juskevice USA 64
Fernando Peralta Uruguay 63
Aaron Mann USA 60
Alexander Chernov Ukraine 60
Assaf Miron Israel 60
Vincent "Jaf" Bonnet France 60
Volker Schindler Germany 60
Yujiro Ogihara Japan 60
Langhans Michael Germany 59
Andy Neilson United Republic Of Writonia 58
Stephen Correia - tumtum73 USA 58
rlrcstr USA 57
Glynn Williams England 56
Adam Richards Cubicletania 55
David Neufeld Canada 55
Erik G. Bitemo Hungary 55
Ismael Serrano USA 55
Joe Ostrander USA 55
Unmesh Gundecha India 54
Mark Jansen The Netherlands 51
Vladimir Stepic Macedonia 50
Chris Griffiths Australia 45
Joshua Taylor USA 45
Matthew Kelly New Zealand 45
Sysadmin Stickler USA 43
Chris Barber USA 41
DS316 Scotland 40
Frodekommode Norway 40
Marjolein Jongstra The Netherlands 40
Roy Darnell USA 40
Christopher G. Lewis USA 38
Dick Salmon USA 35
Krzysztof Bloniarz Poland 35
Tom Glowacki USA 35
Witchakorn Kamolpornwijit Thailand 35
Tomislav Herceg Croatia 31
Dwight Trimble Canada 30
Fredrik Wall Sweden 30
impeeza Colombia 30
Michael Gunther No Affiliation 30
Milo Gancarz Canada 30
N3QGO USA 30
Necip TOMURCUK Turkey 30
Olivier Dalla Rosa France 30
Patrick Massey USA 30
rrizzo USA 30
Vinod Panikar Singapore 29
Josh Fitzgerald USA 28
Bushwhacker Kurdistan 25
David M. Williams Australia 25
Guy Melamed Israel 25
Jason Scheffelmaer USA 25
Jason Yeo Australia 25
Milorad Nikolic Austria 25
Nelnandez USA 25
qsilverx England 25
Richard Manion USA 25
Ryan Youngs USA 25
Daniel Trochez Colombia 20
Jon Warnken Hohenwald 20
newton3010 Gerald Smith 20
Oko Da No Affiliation 20
rwizard54 USA 20
S Coleman USA 20
Thomas Westrick USA 20
Brett Volkmer Australia 15
Emilio Raggi United Arab Emirates 15
George Entecott England 15
JustKillinTime Canada 15
Raphael Simmons aka Dejacpp USA 15
RasmusVoss Denmark 15
Rudi Germany 15
Sankar Muthaiah India 15
Steve Mellor Scotland 15
Chris Ferony USA 13
David Linker Australia 12
Antony Smoothey England 10
Blahcubed USA 10
EZ USA 10
Flavius Romania 10
Joe Roten USA 10
Kevin Tavera USA 10
Rhoderick Milne United Kingdom 10
Tim May USA 10
Yuri Kutovoy Russia 10
David Saxon United Kingdom 5
Greg Bugg USA 5
Kent Finkle USA 5
kevshaw USA 5
Lukas Kucera Czech Republic 5
Matt Farrington USA 5
Paul Waite USA 5
Siddharth Nivargi India 5
WSH D:\Test> ' sélection des participants Français
WSH D:\Test> ft arrScores,"","Country Like 'Fr*'","Name|Country|Total"
Name Country Total
---- ------- -----
Gilles LAURENT France 100
Vincent "Jaf" Bonnet France 60
Olivier Dalla Rosa France 30
WSH D:\Test> ' Ah oui ! C'est vrai ! J'ai participé aux Scripting Games 2007
WSH D:\Test> ' de plus les Scripting Guys viennent de m'annoncer (par voie de
WSH D:\Test> ' messagerie) que je vais recevoir prochainement la tant convoitée
WSH D:\Test> ' "Dr. Scripto Bobblehead Doll" !
WSH D:\Test> ' Enjoy !
WSH D:\Test>
|