- 1 year ago
Opening an executable in the current shell using VBS (Windows)
To open an executable in the current shell using VBS (Visual Basic Scripting) on Windows, you can utilize the Shell
object and the Run
method. Here's an example VBS script that opens an executable in the current shell:
vbscriptSet objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /k <path_to_executable>", 1, False
Replace <path_to_executable>
with the actual path to the executable you want to open.
Explanation:
- The
CreateObject("WScript.Shell")
statement creates a new instance of theShell
object. - The
Run
method is called on theShell
object to execute the command. - The command passed to
Run
iscmd /k <path_to_executable>
, wherecmd
is the Windows command prompt and/k
keeps the command prompt open after executing the command. - The
1
parameter specifies to display the command prompt window, andFalse
ensures the script does not wait for the command to complete before continuing.
Save the script with a .vbs
extension (e.g., open_executable.vbs
) and double-click on it to run. It will open the specified executable in the current shell.
Note that running executables in the current shell using VBS may have limitations depending on the executable and the desired behavior. Some executables may spawn new processes or require specific command-line arguments for proper execution. Make sure to adjust the command passed to Run
based on your specific requirements.