Archives de catégorie : Scripting

vbscript – WshShell.RegRead / RegWrite

**METHOD:** `shell.RegRead(path) / shell.RegWrite(path, value[, type])`

**Description**
Lit/écrit des valeurs dans le registre Windows.

**Syntax**
`shell.RegRead(path) / shell.RegWrite(path, value[, type])`

**Paramètres**
– `path` : Chemin complet (ex: « HKCUSoftware…ValueName »).

**Retour**
Valeur lue (RegRead) / rien (RegWrite).

**Notes**
– Attention : permissions nécessaires selon la ruche/clé.
– Toujours tester en environnement de dev avant prod.

**Exemples**
« `vb
Dim shell
Set shell = CreateObject(« WScript.Shell »)
‘ Exemple: écrire puis relire (HKCU)
shell.RegWrite « HKCUSoftwarepleasantDemo », « ok », « REG_SZ »
WScript.Echo shell.RegRead(« HKCUSoftwarepleasantDemo »)
« `

**Voir aussi**
`WshShell.RegDelete`

vbscript – If…Then…Else

**STATEMENT:** `If…Then…Else`

**Description**
Branche conditionnelle classique.

**Syntax**
`If…Then…Else`

**Paramètres**
– *(aucun)*

**Notes**
– Astuce : active `Option Explicit` dans tes scripts pour éviter les variables mal orthographiées.

**Exemples**
« `vb
Dim x
x = 10
If x > 5 Then
WScript.Echo « x est > 5 »
Else
WScript.Echo « x est <= 5" End If ```

vbscript – Scripting.Dictionary

**HOWTO:** `Set d = CreateObject(« Scripting.Dictionary »)`

**Description**
Crée un dictionnaire clé/valeur (très pratique pour indexer des données).

**Syntax**
`Set d = CreateObject(« Scripting.Dictionary »)`

**Paramètres**
– *(aucun)*

**Retour**
Objet `Scripting.Dictionary`.

**Exemples**
« `vb
Dim d
Set d = CreateObject(« Scripting.Dictionary »)
d.Add « host », « pleasant.ch »
If d.Exists(« host ») Then WScript.Echo d.Item(« host »)
« `

**Voir aussi**
`Dictionary.Add`, `Dictionary.Exists`, `Dictionary.Keys`

vbscript – For Each…Next

**STATEMENT:** `For Each…Next`

**Description**
Boucle sur une collection (ex: Dictionary, FSO.Files, etc.).

**Syntax**
`For Each…Next`

**Paramètres**
– *(aucun)*

**Notes**
– Astuce : active `Option Explicit` dans tes scripts pour éviter les variables mal orthographiées.

**Exemples**
« `vb
Dim d, k
Set d = CreateObject(« Scripting.Dictionary »)
d.Add « a », 1
d.Add « b », 2
For Each k In d.Keys
WScript.Echo k & « = » & d.Item(k)
Next
« `

vbscript – Select Case

**STATEMENT:** `Select Case`

**Description**
Alternative propre à une chaîne de If/ElseIf.

**Syntax**
`Select Case`

**Paramètres**
– *(aucun)*

**Notes**
– Astuce : active `Option Explicit` dans tes scripts pour éviter les variables mal orthographiées.

**Exemples**
« `vb
Dim role
role = « admin »
Select Case LCase(role)
Case « admin »
WScript.Echo « Accès complet »
Case « user »
WScript.Echo « Accès standard »
Case Else
WScript.Echo « Accès inconnu »
End Select
« `