Au Fil du Temps


Accueil
'-----------------------------------------------  VARENV.WSC ---------------------------'
'-- DESCRIPTION : 
'--		- Gestion des variables environnements : contexte USER,SYSTEM,PROCESS
'--     - Utilisation d'un scriptlet en VBSCRIPT  
'-- ENTREE : -
'-- SORTIE : Affichage des variables en html/javascript 
'---------------------------------------------------------------------------------------------------------


<?xml version="1.0"?>
<component id="component.ai">

<?component error="true" debug="true"?>

'-------------------------------------------------------------------------------------- 
' L'inscription ci-dessous est une étape obligatoire si on n'utilise pas GetObject 
' Les informations sont écrites sous HKCR\CLSID\{..classid...}\
' Pour l'obtention du CLSID, exécuter le wizard WSC. Un fichier squellette sera générer.

Téléchargez Windows Script Component Wizard ScriptWz.exe
'-------------------------------------------------------------------------------------- <registration description="VarEnv" progid="VarEnv.AFDT" version="1.00" classid="{ff93b6f3-8324-46a7-8367-ff0fb4dd404f}" > </registration> '--------------------------------------------------------------------------------------- ' Chaque méthode supplémentaire est référencé avec les paramètres ' Var = Nom de la variable ' Value = Valeur de la variable ' Env = Contexte de la variable [USER|SYSTEM|PROCESS] '--------------------------------------------------------------------------------------- <public> <property name="Environnement"> <get/> <put/> </property> <method name="GetVar"> <PARAMETER name="Var"/> </method> <method name="GetListVar"> <PARAMETER name="Env"/> </method> <method name="GetNbVar"> <PARAMETER name="Env"/> </method> <method name="AddVar"> <PARAMETER name="Var"/> <PARAMETER name="Value"/> </method> <method name="DelVar"> <PARAMETER name="Var"/> </method> <method name="GetVarEnv"> <PARAMETER name="Var"/> <PARAMETER name="Env"/> </method> <method name="AddVarEnv"> <PARAMETER name="Var"/> <PARAMETER name="value"/> <PARAMETER name="Env"/> </method> <method name="DelVarEnv"> <PARAMETER name="Var"/> <PARAMETER name="Env"/> </method> <method name="Register"> </method> </public> '------------------------------------------------------- ' Début des scripts '------------------------------------------------------- <script language="VBScript"> <![CDATA[ '------------------------------------------------------- ' Par défaut le contexte est initialisé à PROCESS ' ------------------------------------------------------ dim Environnement Environnement = "PROCESS" 'Win98 Process uniquement function get_Environnement() get_Environnement = Environnement end function Sub put_Environnement(NewEnv) Environnement = newEnv end Sub '-------------------------------------------------------- ' La méthode Register (optionnel) n'est pas inclus lors de ' l'éxécution du wizard.Elle permet de générer la bibliothèque ' de script "scriptlet.tlb" ' Selectionner le fichier .WSC puis propriétés. ' 3 options: 1. Inscrire ' 2. Désinscrire ' 3. Générer la bibliothèque ' Sans cette ajout on obtient avec l'option 3. cette fenêtre: '----------------------------------------------------------- Sub Register() Set oTL = CreateObject("Scriptlet.TypeLib") oTL.AddURL "VarEnv.WSC" ' Script component URL. oTL.Path = "VarEnv.tlb" ' .tlb path. oTL.Doc = "" ' Documentation string. oTL.GUID = "{a1e1e3e0-a252-11d1-9fa1-00a0c90fffc0}" oTL.Name = "VarEnvComponentTLib" ' Internal name for tlb. oTL.MajorVersion = 1 oTL.MinorVersion = 0 oTL.Reset ' Clear list of URLs in AddURL/. oTL.Write ' Write tlib to disk. End sub function GetVar(var) getVar = GetVarEnv(var,get_Environnement) end function Sub AddVar(var,value) put_environnement "SYSTEM" AddVarEnv var,value,get_Environnement end Sub Sub DelVar(var) put_environnement "SYSTEM" DelVarEnv var,get_Environnement end Sub function GetNbVar(Env) Dim WSHShell Dim wshEnv Dim strVar set WSHShell = CreateObject("Wscript.shell") Set wshEnv = WSHShell.Environment(Env) GetNbVar = wshEnv.length Set WSHShell = Nothing Set WSHEnv = Nothing end function function GetVarEnv(Var,Env) Dim WSHShell Dim wshEnv Dim strVar set WSHShell = CreateObject("Wscript.shell") Set wshEnv = WSHShell.Environment(Env) If wshEnv(var) <> "" Then strVar = WSHShell.ExpandEnvironmentStrings(wshEnv(var)) End If Set WSHShell = Nothing Set WSHEnv = Nothing GetVarEnv = strVar 'strVar = vide Variable inexistante end function function GetListVar(env) Dim WSHShell Dim wshEnv Dim strVar Dim strenv strenv = "" strvar = "" set WSHShell = CreateObject("Wscript.shell") Set wshEnv = WSHShell.Environment(env) for each strenv in wshEnv aEnv = split(strenv,"=",-1,1) If( wshEnv(aEnv(0)) <> "") Then ' Saute les lignes vides dans la table env ex:PROCESS 1ere ligne strVar = strvar & aEnv(0) & "=" & WSHShell.ExpandEnvironmentStrings(wshEnv(aEnv(0))) & vbCrlf End if next Set WSHShell = Nothing Set WSHEnv = Nothing GetListVar = strVar 'strVar = vide Variable inexistante end function Sub AddVarEnv(Var,value,Env) Dim WSHShell Dim wshEnv Dim strVar set WSHShell = CreateObject("Wscript.shell") Set wshEnv = WSHShell.Environment(Env) wshEnv(var) = value Set WSHShell = Nothing Set WSHEnv = Nothing end Sub Sub DelVarEnv(Var,Env) Dim WSHShell Dim wshEnv Dim strVar set WSHShell = CreateObject("Wscript.shell") Set wshEnv = WSHShell.Environment(Env) wshEnv.Remove(var) Set WSHShell = Nothing Set WSHEnv = Nothing end Sub ]]> </script> </component> '---------------------------------------------------------------- ' Pour voir le résultat: ' Téléchargez varenv.zip et décompresser varenv.wsc et varenv.htm ' dans le même répertoire ' 1. Inscrire varenv.wsc via ses propriétés ' 2. Exécutez varenv.htm avec Internet Explorer (Activer ActiveX)
'----------------------------------------------------------------