.ShellExecute - VBScript
.ShellExecute
Execute a specified executable file or document, or open a specified web page.
Syntax
.ShellExecute(FilePath, Operation, Parameters, ShowWindow)
Options/Flags
Parameter | Type | Description
——————— | ———– | ———–
FilePath | String | Specifies the path and filename of the executable file, document, or web page to open.
Operation | String | Specifies the operation to perform on the file or document. Can be “open”, “edit”, “print”, or “explore”.
Parameters | String | Specifies any parameters to pass to the executable file or document.
ShowWindow | Integer | Specifies how the file or document window should be displayed. Can be one of the following:
- 1 (SW_HIDE)
- 2 (SW_MINIMIZE)
- 3 (SW_MAXIMIZE)
- 4 (SW_RESTORE)
Examples
Simple:
.ShellExecute "notepad.exe", "open", "test.txt"
With Parameters:
.ShellExecute "myapp.exe", "open", "/parameter1:value1 /parameter2:value2"
Open Web Page:
.ShellExecute "iexplore.exe", "open", "https://www.example.com"
Common Issues
- File Not Found: Ensure that the specified file path is correct.
- Access Denied: Verify that you have sufficient permissions to open the file or document.
- Invalid Operation: Check that the operation you are attempting is supported by the file type.
Integration
- Create a Shortcut: Create a shortcut to a file or document using:
Set wshShell = WScript.CreateObject("WScript.Shell")
wshShell.ShellExecute "explorer.exe", "open,filename.lnk"
- Open Recent Documents: Access the list of recently opened documents using:
Set wshShell = WScript.CreateObject("WScript.Shell")
documents = wshShell.SpecialFolders("Recent")
documents.self.Items
Related Commands
- .Run: Executes a program or command.