Archives de catégorie : Scripting

vbscript – WshShell.ExpandEnvironmentStrings

**METHOD:** `shell.ExpandEnvironmentStrings(string)`

**Description**
Développe les variables d’environnement (ex: `%TEMP%`).

**Syntax**
`shell.ExpandEnvironmentStrings(string)`

**Paramètres**
– `string` : Chaîne contenant des variables %VAR%.

**Retour**
Chaîne développée.

**Exemples**
« `vb
Dim shell
Set shell = CreateObject(« WScript.Shell »)
WScript.Echo shell.ExpandEnvironmentStrings(« %TEMP% »)
« `

**Voir aussi**
`WshShell.Environment`

vbscript – WshShell.Environment

**METHOD:** `shell.Environment(scope)`

**Description**
Accède aux variables d’environnement (Process/User/System).

**Syntax**
`shell.Environment(scope)`

**Paramètres**
– `scope` : « PROCESS », « USER » ou « SYSTEM ».

**Retour**
Collection de variables d’environnement.

**Exemples**
« `vb
Dim shell, env
Set shell = CreateObject(« WScript.Shell »)
Set env = shell.Environment(« PROCESS »)
WScript.Echo env(« COMPUTERNAME »)
« `

**Voir aussi**
`WshShell.ExpandEnvironmentStrings`

vbscript – WshShell.CreateShortcut

**METHOD:** `shell.CreateShortcut(pathToLnk)`

**Description**
Crée/ouvre un raccourci `.lnk` (puis définir TargetPath, Arguments, etc.).

**Syntax**
`shell.CreateShortcut(pathToLnk)`

**Paramètres**
– `pathToLnk` : Chemin du .lnk.

**Retour**
Objet `WshShortcut`.

**Exemples**
« `vb
Dim shell, sc
Set shell = CreateObject(« WScript.Shell »)
Set sc = shell.CreateShortcut(« C:tempdemo.lnk »)
sc.TargetPath = « notepad.exe »
sc.Description = « Demo pleasant »
sc.Save
« `

**Voir aussi**
`WshShortcut.Save`

vbscript – Dictionary.Add

**METHOD:** `d.Add key, item`

**Description**
Ajoute une entrée clé/valeur dans un `Scripting.Dictionary`.

**Syntax**
`d.Add key, item`

**Paramètres**
– `key` : Clé (souvent String).
– `item` : Valeur associée.

**Retour**
Aucun.

**Exemples**
« `vb
Dim d
Set d = CreateObject(« Scripting.Dictionary »)
d.Add « a », 1
WScript.Echo d.Item(« a »)
« `

**Voir aussi**
`Dictionary.Exists`, `Dictionary.Item`

vbscript – WshNetwork.MapNetworkDrive

**METHOD:** `net.MapNetworkDrive localName, remoteName[, updateProfile[, user[, password]]]`

**Description**
Mappe un lecteur réseau (ex: Z: -> \servershare).

**Syntax**
`net.MapNetworkDrive localName, remoteName[, updateProfile[, user[, password]]]`

**Paramètres**
– `localName` : Lettre (ex: « Z: »).
– `remoteName` : Partage UNC (ex: « \servershare »).

**Retour**
Aucun.

**Notes**
– Peut nécessiter des droits/identifiants.
– Attention en environnement corporate (politiques, MFA, etc.).

**Exemples**
« `vb
Dim net
Set net = CreateObject(« WScript.Network »)
‘ net.MapNetworkDrive « Z: », « \servershare »
WScript.Echo « Mapping prêt (décommenter pour l’exécuter) »
« `

**Voir aussi**
`WshNetwork.RemoveNetworkDrive`