Soru

Zorluk: ZorBasic Scripting Languages and Constructs

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?

  1. Use the WScript.Shell object's ExpandEnvironmentStrings method passing "%DEPARTMENT%" as the argument.Cevap
  2. B
    Enclose the environment variable name in dollar sign brackets such as ${DEPARTMENT}.
  3. C
    Prefix the variable with a dollar sign such as $env:DEPARTMENT.
  4. D
    Execute 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

1
Identify the scripting language and runtime environment.
The file uses VBScript (.vbs), which runs under the WScript.exe or CScript.exe Windows Script Host engine.
VBScript does not natively expand Windows shell syntax like %VAR% in string literals.
2
Determine the proper object method to access system environment variables in VBScript.
The WScript.Shell object provides access to system environment variables using WshShell.ExpandEnvironmentStrings("%DEPARTMENT%").
VBScript relies on Windows Script Host COM objects to interact with system-level environment variables.

Anahtar Kavram

VBScript Environment Variable Retrieval and Scripting Host Constructs
Tahmini Süre:2m 0s
Bu soruyu puanla