WSH Shell : Les modules externes - Gilles LAURENT .fr

Mar 18, 2007 - Volker Schindler. Germany. 60 ... Christopher G. Lewis. USA. 38 glsft.free.fr ... WSH D:\Test> ' "Dr. Scripto Bobblehead Doll" ! WSH D:\Test> ...
13KB taille 1 téléchargements 284 vues
glsft.free.fr

WSH Shell : Les modules externes Soumis par Gilles LAURENT 18-03-2007 Dernière mise à jour : 08-10-2007

Aperçu des fonctionnalités de la console WSH ShellInté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.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.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 () http://glsft.free.fr

Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

' 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. _ _ _ ___ _ _ ___ _ http://glsft.free.fr

_ _ Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

| | | |/ __>| | | / __>| |_ ___ | || | | | | |\__ \| | \__ \| . |/ ._>| || | |__/_/ ' 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 ---Alan Dunbar Alan Mosley Alan Roberson Alex Duckworth AlioTheFool http://glsft.free.fr

Country ------Canada Australia USA Australia USA

Total ----100 100 100 100 100 Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

Ben Simkins Blackhawk Bob Stammers Chris Bland Chris Osborne Christian Pfeiffer Clifford Williamson, III Clinton Huff Courtney Newman Craig Naumann Curtis J. O'Connell Dan Richardson Darren Malik Dave E Dave Rosen Dave Wyatt David Coles Dennis G. Landsem djhayman DrBayer Ed Z Eelco Ligtvoet Eric Payne Erik Renes Fábio de Paula Junior Francis de la Cerna Frank den Haan Frank Fattizzi Fred Jenkins Geoffrey Grinton Gilles LAURENT Gordon Yuen Gyorgy Nemesmagasi H. S. H2Data Helder Sepulveda Homer Yu Hong Quan YU Imran Hashim Jakub Niedzwiedz James Ward Jan Kuvaja Jarno Mäki Jason Clement Jason Joy Jean - JMST Jerry G Jerzy Prusinski John Medwid John Reichenbach Josh Bradbury Luis Martín Caballero Marcus L. Farmer Mark B Matthew R. Davis Matto Maureen Farrell Michaela Doil micra Mike Holden Miles Willmek MrRat Nick Ford Patrick Donahue Patrick O'Connell http://glsft.free.fr

Switzerland 100 Canada 100 No Affiliation 100 Canada 100 USA 100 Austria 100 USA 100 USA 100 USA 100 Australia 100 USA 100 USA 100 USA 100 United Kingdom 100 Israel 100 USA 100 Australia 100 Norway 100 Australia 100 Vandyland 100 USA 100 The Netherlands 100 USA 100 The Netherlands 100 Brazil 100 USA 100 The Netherlands 100 USA 100 USA 100 Australia 100 France 100 Bmraarykduesn 100 Hungary 100 Denmark 100 Australia 100 Cuba Libre 100 ITExpert 100 China 100 Pakistan 100 Poland 100 USA 100 Sweden 100 Finland 100 USA 100 USA 100 Belgium 100 USA 100 Poland 100 DSG 100 USA 100 Kazakhstan 100 Spain 100 USA 100 USA 100 USA 100 Australia 100 USA 100 Germany 100 Poland 100 Albania 100 Canada 100 USA 100 England 100 USA 100 USA 100 Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

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 http://glsft.free.fr

Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

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 http://glsft.free.fr

Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

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" http://glsft.free.fr

Propulsé par Joomla!

Généré: 29 July, 2018, 05:07

glsft.free.fr

Name Country ---------Gilles LAURENT France Vincent "Jaf" Bonnet France Olivier Dalla Rosa France

Total ----100 60 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>

http://glsft.free.fr

Propulsé par Joomla!

Généré: 29 July, 2018, 05:07