WSH Shell : Assistance Windows Ini |
Écrit par Gilles LAURENT | |
03-10-2007 | |
Aperçu des fonctionnalités de la console WSH Shell Assistance Windows Ini à l'aide du module _wshIni.inc 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 18:29:18 and WSH Shell is up ! Ready. WSH D:\Test> ' utilisation du module externe _wshIni.inc WSH D:\Test> ' tous les modules (classes) sont chargés au démarrage de la WSH D:\Test> ' console donc il ne reste plus qu'à créer une instance WSH D:\Test> Set oIni=New wshIni WSH D:\Test> ' détermination des membres (méthodes et propriétés) WSH D:\Test> gm(oIni) Category Name -------- ---- Function Dump () Function GetValue (strSection, strKey) Sub Load (strFileName) Sub Save () Sub SetValue (strSection, strKey, strValue) Property Keys (strSection) Property Sections Property strFileName Property Version WSH D:\Test> ' chargement du fichier au format Windows .ini WSH D:\Test> oIni.Load "D:\Test\Test.ini" WSH D:\Test> ' le fichier est chargé en mémoire WSH D:\Test> ' affichage formaté du contenu WSH D:\Test> ft oIni.Dump,"","","*" Section Key Value ------- --- ----- section1 key11 value11 section1 key12 value12 section1 key13 value13 section2 key21 value21 section2 key22 value22 section3 key31 value31 WSH D:\Test> ' affichage des sections WSH D:\Test> echo $(oIni.Sections) section1 section2 section3 WSH D:\Test> ' extraction des sections, des clés et des valeurs WSH D:\Test> % strSection In oIni.Sections { >> echo "[" & strSection & "]" >> % strKey In oIni.Keys(strSection) { >> echo strKey & "=" & oIni.GetValue(strSection,strKey) >> } >> } >> [section1] key11=value11 key12=value12 key13=value13 [section2] key21=value21 key22=value22 [section3] key31=value31 WSH D:\Test> ' ajout d'une clé dans la section "section2" WSH D:\Test> oIni.SetValue("section2","key23","value23") :: An error occured (1044) :: L'appel d'une fonction Sub n'admet pas de parenthèses. WSH D:\Test> oIni.SetValue "section2","key23","value23" WSH D:\Test> ft oIni.Dump,"","","*" Section Key Value ------- --- ----- section1 key11 value11 section1 key12 value12 section1 key13 value13 section2 key21 value21 section2 key22 value22 section2 key23 value23 section3 key31 value31 WSH D:\Test> ' ajout d'une nouvelle section "section4" WSH D:\Test> oIni.SetValue "section4","key41","value41" WSH D:\Test> ft oIni.Dump,"","","*" Section Key Value ------- --- ----- section1 key11 value11 section1 key12 value12 section1 key13 value13 section2 key21 value21 section2 key22 value22 section2 key23 value23 section3 key31 value31 section4 key41 value41 WSH D:\Test> ' suppression de la clé "key12" de la section "section1" WSH D:\Test> oIni.SetValue "section1","key12",Null WSH D:\Test> ft oIni.Dump,"","","*" Section Key Value ------- --- ----- section1 key11 value11 section1 key13 value13 section2 key21 value21 section2 key22 value22 section2 key23 value23 section3 key31 value31 section4 key41 value41 WSH D:\Test> ' suppression de la section "section2" WSH D:\Test> oIni.SetValue "section2",Null,Null WSH D:\Test> ft oIni.Dump,"","","*" Section Key Value ------- --- ----- section1 key11 value11 section1 key13 value13 section3 key31 value31 section4 key41 value41 WSH D:\Test> ' toutes les modifications se font en mémoire WSH D:\Test> ' pour le vérifier on exécute une commande externe WSH D:\Test> @type d:\test\test.ini [section1] key11=value11 key12=value12 key13=value13 [section2] key21=value21 key22=value22 [section3] key31=value31 WSH D:\Test> ' le fichier chargé est "d:\test\test.ini" WSH D:\Test> echo oIni.strFileName D:\Test\Test.ini WSH D:\Test> ' sauvegarde du fichier WSH D:\Test> ' nous allons ici le sauvegarder sous un autre nom WSH D:\Test> oIni.strFileName="D:\Test\Test.new" WSH D:\Test> oIni.Save WSH D:\Test> ' vérification à l'aide d'une commande externe WSH D:\Test> @type d:\test\test.new [section1] key11=value11 key13=value13 [section3] key31=value31 [section4] key41=value41 WSH D:\Test> ' pour obtenir l'aide sur la classe wshIni WSH D:\Test> _gethelp * wshIni Name Category Synopsis ---- -------- -------- Dump Function Returns a formated array of the currently loaded initi... GetValue Function Returns the value of the specified key in the specifie... Keys Property Returns all the keys (array) of the specified section. Load Sub Loads the specified initialization file. Save Sub Saves to disk the previously loaded initialization fil... Sections Property Returns all the sections (array) of the loaded initial... SetValue Sub Updates the previously loaded initialization file. strFileName Property The name of the loaded / saved initialization file. Version Property Returns the class release version. WSH D:\Test> ' Enjoy ! WSH D:\Test> |
|
Dernière mise à jour : ( 03-10-2007 ) |