A network technician is debugging an automated logon script executed during Windows user sign-in. The script is written in VBScript (`.vbs`) and is intended to append the logged-in user's department name to a log file by accessing the system environment variable `%DEPARTMENT%`. However, when executed, the script treats the variable name as a literal text string rather than expanding its stored value. Which of the following script modifications should the technician implement to correctly retrieve the environment variable value within VBScript?
- Use the WScript.Shell object's ExpandEnvironmentStrings method passing "%DEPARTMENT%" as the argument.Cevap
- BEnclose the environment variable name in dollar sign brackets such as ${DEPARTMENT}.
- CPrefix the variable with a dollar sign such as $env:DEPARTMENT.
- DExecute the script file using cmd.exe instead of cscript.exe or wscript.exe.
Cevap
The technician must use the WScript.Shell object's ExpandEnvironmentStrings method (or Environment property) to retrieve and expand environment variable values within a VBScript environment.
In Windows administration, VBScript (.vbs) runs under Windows Script Host (CScript/WScript). Unlike Batch scripts (.bat), VBScript does not evaluate percent-delimited string literals (%VARIABLE%) automatically. Accessing operating system environment variables in VBScript requires instantiating the WScript.Shell object and invoking the ExpandEnvironmentStrings method.
Adım Adım Çözüm
Anahtar Kavram
VBScript Environment Variable Retrieval and Scripting Host Constructs
Tahmini Süre:2m 0s