WSH Shell : Présentation générale |
Écrit par Gilles LAURENT | |
09-03-2007 | |
Aperçu des fonctionnalités de la console WSH Shell Présentation générale de la console 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 13:45:15 and WSH Shell is up ! Ready. WSH D:\Test> ' la console instancie automatiquement la classe WSHShell WSH D:\Test> ' cette classe est disponible via l'objet shell WSH D:\Test> WScript.Echo TypeName(shell) WSHShell WSH D:\Test> ' cet objet possède des propriétés et des méthodes WSH D:\Test> ' il est possible d'afficher les membres en faisant appel WSH D:\Test> ' à la méthode GetMembers WSH D:\Test> shell.GetMembers(shell) Category Name -------- ---- Function ArrayToString (arrInputArray) Function CreateObjectWithConstants (strProgID) Function DownloadString (strUrl, arrRetCode) Sub FormatTable (arrTableContent, strSortCtrl, strFilterCtrl, strColumn... Sub GetAlias (strAlias) Sub GetConstants (Object) Function GetFileContent (strFilename) Sub GetMembers (Object) Sub Include (strFilename) Function Match (strString, strPattern) Sub SetAlias (strAlias, strCommand) Function SortArray (arrInputArray) Sub StartShell () Sub StopShell () Function StringToArray (strInputString) Property bDebug Property hWnd Property Name Property nTableColumnWidth Property Path Property Pid Property strDelims Property strTableFieldSep Property Tid Property Version WSH D:\Test> ' dans le but d'accélerer la saisie des commandes, la console WSH D:\Test> ' supporte la définition d'alias WSH D:\Test> ' affichage des alias définis par défaut WSH D:\Test> shell.GetAlias "*" Alias Definition ----- ---------- % For Each @ Shell.StringToArray \$ Shell.ArrayToString { ` } Next co Shell.CreateObjectWithConstants echo WScript.Echo foreach For Each ft Shell.FormatTable ga Shell.GetAlias gc Shell.GetConstants gfc Shell.GetFileContent gm Shell.GetMembers go GetObject quit Shell.StopShell sa Shell.SetAlias write WScript.StdOut.Write WSH D:\Test> ' il est donc possible d'écrire la commande suivante WSH D:\Test> Set oFs=co("Scripting.FileSystemObject") WSH D:\Test> gm(oFs) Category Name -------- ---- Function BuildPath (Path, Name) Sub CopyFile (Source, Destination, [OverWriteFiles]) Sub CopyFolder (Source, Destination, [OverWriteFiles]) Function CreateFolder (Path) Function CreateTextFile (FileName, [Overwrite], [Unicode]) Sub DeleteFile (FileSpec, [Force]) Sub DeleteFolder (FolderSpec, [Force]) Function DriveExists (DriveSpec) Function FileExists (FileSpec) Function FolderExists (FolderSpec) Function GetAbsolutePathName (Path) Function GetBaseName (Path) Function GetDrive (DriveSpec) Function GetDriveName (Path) Function GetExtensionName (Path) Function GetFile (FilePath) Function GetFileName (Path) Function GetFileVersion (FileName) Function GetFolder (FolderPath) Function GetParentFolderName (Path) Function GetSpecialFolder (SpecialFolder) Function GetStandardStream (StandardStreamType, [Unicode]) Function GetTempName () Sub MoveFile (Source, Destination) Sub MoveFolder (Source, Destination) Function OpenTextFile (FileName, [IOMode], [Create], [Format]) Property Drives WSH D:\Test> ' les constantes sont automatiquement importées WSH D:\Test> echo ForReading 1 WSH D:\Test> ' la saisie des blocs de commandes peut se faire de plusieurs WSH D:\Test> ' manières. WSH D:\Test> ' la méthode classique 'multilignes' : WSH D:\Test> For i=1 To 5 ` >> write i & " " >> Next >> 1 2 3 4 5 WSH D:\Test> ' la première ligne d'un bloc se termine obligatoirement par WSH D:\Test> ' le caractère "`". Le bloc de commandes est exécuté après la WSH D:\Test> ' première ligne vide rencontrée WSH D:\Test> ' en utilisant les alias : WSH D:\Test> For i=1 To 5 { >> write i & " " >> } >> 1 2 3 4 5 WSH D:\Test> ' une autre méthode consiste à utiliser le caractère de séparation WSH D:\Test> ' des commandes ":". Un avantage de cette technique est de WSH D:\Test> ' faciliter le rappel de commande et ainsi d'être en mesure de WSH D:\Test> ' rejouer le bloc plus facilement via le support Doskey : WSH D:\Test> For i=1 To 5: write i & " ": Next 1 2 3 4 5 WSH D:\Test> ' la console permet de simplifier quelques actions WSH D:\Test> ' par exemple la mise en page sous forme de tableau WSH D:\Test> Dim arrUsers(5) WSH D:\Test> ' définition des colonnes WSH D:\Test> arrUsers(0)="Lastname|Firstname|Age|Country" WSH D:\Test> ' alimentation du tableau WSH D:\Test> arrUsers(1)="Doe|John|36|USA" WSH D:\Test> arrUsers(2)="Smith|Bob|18|Canada" WSH D:\Test> arrUsers(3)="Dupont|Marc|24|France" WSH D:\Test> arrUsers(4)="Eliot|Billy|25|United Kingdom" WSH D:\Test> arrUsers(5)="Laurent|Gilles|36|France" WSH D:\Test> ' définition du séparateur de colonnes WSH D:\Test> shell.strTableFieldSep="|" WSH D:\Test> ' affichage des données WSH D:\Test> ' utilisation de la méthode FormatTable (alias ft) WSH D:\Test> ft arrUsers,"","","*" Lastname Firstname Age Country -------- --------- --- ------- Doe John 36 USA Smith Bob 18 Canada Dupont Marc 24 France Eliot Billy 25 United Kingdom Laurent Gilles 36 France WSH D:\Test> ' il est possible de trier les colonnes WSH D:\Test> ft arrUsers,"Lastname","","*" Lastname Firstname Age Country -------- --------- --- ------- Doe John 36 USA Dupont Marc 24 France Eliot Billy 25 United Kingdom Laurent Gilles 36 France Smith Bob 18 Canada WSH D:\Test> ft arrUsers,"Age Desc","","*" Lastname Firstname Age Country -------- --------- --- ------- Laurent Gilles 36 France Doe John 36 USA Eliot Billy 25 United Kingdom Dupont Marc 24 France Smith Bob 18 Canada WSH D:\Test> ' pour obtenir de l'aide sur les méthodes et propriétés ainsi WSH D:\Test> ' que sur les fonctions builtin WSH D:\Test> _gethelp Name Category Synopsis ---- -------- -------- _break builtin Aborts the current statement, like CTRL/... _cleanlss builtin Deletes all defined (Dim'ed) variables s... _gethelp builtin Provides help and usage information abou... _loadhistory builtin Loads console command history from a fil... _more builtin Displays one screen of output at a time. _nomore builtin Enables automatic page scrolling. _nowrap builtin Disables automatic line wrapping. The ou... _savehistory builtin Saves console command history to a file. _screensnap builtin Takes a console screen buffer snapshot a... _starttranscript builtin Starts a new transcript. All input and o... _stoptranscript builtin Stops and closes the currently started t... _wrap builtin Enables automatic line wrapping. The out... ArrayToString Function Combines substrings (elements) of an arr... bDebug Property Enables or disables the internal debug m... CreateObjectWithConstants Function Creates and returns a reference to an Au... DownloadString Function Opens an HTTP connection to a server at ... FormatTable Sub Takes a data array on input and formats ... GetAlias Sub Returns a list of your WSH Shell aliases. GetConstants Sub Returns the constants defined for the sp... GetFileContent Function Puts a file content into an array of lin... GetMembers Sub Gets the members (methods and properties... hWnd Property The WSH Shell console window handle. Include Sub Loads and execute a VBScript file in the... Match Function Determines whether the search pattern oc... Name Property The WSH Shell name (aka 'Windows Script ... nTableColumnWidth Property Defines the maximum width of a table for... Path Property Returns the full path from which the cur... Pid Property Returns the WSH Shell console Process Id. SetAlias Sub Creates or changes an alias (alternate n... SortArray Function Takes a strings array on input and retur... StartShell Sub Starts the Windows Script Host (WSH) She... StopShell Sub Stops the Windows Script Host (WSH) Shel... strDelims Property Gets or sets the array/string delimiter.... StringToArray Function Takes a string value on input and return... strTableFieldSep Property Specifies the field/column separator. Us... Tid Property Returns the WSH Shell console Thread Id. Version Property Returns the WSH Shell current release ve... wshAdsi HelpFile WSH Adsi Methods and Properties wshCmdLine HelpFile WSH Command Line Parameters wshIni HelpFile WSH Ini Methods and Properties wshShell HelpFile WSH Shell Methods and Properties wshWmi HelpFile WSH Wmi Methods and Properties WSH D:\Test> ' Enjoy ! WSH D:\Test> |
|
Dernière mise à jour : ( 03-10-2007 ) |