How is the Wscript object utilized?
The Wscript object is a built-in object of Windows Script Host (WSH) used for executing scripts and controlling the script execution environment. Here are some commonly used methods of the Wscript object:
- CreateObject: creates and returns a reference to a COM component.
For example: Set objExcel = CreateObject(“Excel.Application”) - Pause the execution of the script for a period of time, measured in milliseconds.
For example: Wscript.Sleep 5000. - Echo: Output a message to the command line window when the script is running.
For example: Wscript.Echo “Hello, World!” - Stop: Terminates the script’s execution.
For example: Wscript.Quit - Create a shortcut: this will create a shortcut.
For instance: Set objShortcut = Wscript.CreateShortcut(“C:\Shortcut.lnk”) - Execute the executable file, script, or command.
Example: Wscript.Run “notepad.exe” - Shell: Create and return a reference to a Windows Shell object for performing Shell-related operations. For example: Set objShell = Wscript.CreateObject(“Wscript.Shell”)
These are just common methods of the Wscript object, there are other methods that can be used in the script as needed.