How to Run an .exe file on PowerShell
As a developer and system administrators, it is a common task to run an .exe file in PowerShell. Unlock the full potential PowerShell with the simple guide that walk you through executing application effortlessly. Using PowerShell as a centralized management tool simplifies running .exe files, especially in complex scenarios where automation, control, and scripting are needed. Follow the next guide, we will show three methods of running .exe file on you Windows PowerShell.
Method 1. Direct Execution
It is a simple and quick method to run and executable(.exe) file through direct execution in PowerShell, follow the next straightforward steps:
Step 1. Open PowerShell: Search for PowerShell in the Start Meun and launch it.
Step 2. Use the Ampersand (&) Symbol: Type the ampersand symbol followed by a space, then enter the full path to your .exe file. For example:
C:\Path\To\YourFile.exe
Step 3. Executing from Current Directory: IF you are already in the directly where the .exe file is located, you can run it directly prefixing it with .\`. For example:
.\YourFile.exe
Step 4. Drag and Drop Method: To easily get the path, you can drag and drop the .exe file into the PowerShell windows. This automatically fills in the correct path.
Example Command:
If you want to run a file named `File_3.62.2_win62-setup.exe` stored in a folder called “ Zip Files” on your desktop, you would use:
C:\Users\YourUsername\Desktop\Zip Files\File_3.62.2_win64-setup.exe"
Method 2. Using Start-Process Cmdlet
To run an EXE file in PowerShell , you can use the Start-Process cmdlet. This method provides more control and is useful for running applications with specific parameters. Follow these steps:
Step 1. On the PowerShell window, you can use the following basic command syntax to start the executable:
Start-Process -FilePath "C:\Path\To\YourFile.exe
Step 2. If the executable requires parameters, use the `-ArgumentList` parameter:
Start-Process -FilePath "C:\Path\To\YourFile.exe" -ArgumentList "arg1", "arg2"
Step 3. To run an executable with administrative rights, add the `-Verb RunAs` parameter:
Start-Process -FilePath "C:\Path\To\YourFile.exe" -Verb RunAs
Step 4. You can control how the window appears using the `WindowStyle` parameter:
Start-Process -FilePath "C:\Path\To\YourFile.exe" -WindowStyle Maximized
Example Command:
Running as administrator:
Start-Process -FilePath "C:\Program Files\MyApp\MyApp.exe" -Verb RunAs
Additional Notes:
- The `Start-Process` cmdlet runs processes asynchronously, meaning it returns control to PowerShell Immediately while the new process runs independently.
- You can also redirect output and error streams to files using parameters like `-RedirectStandardOutput` and `-RedirectStandardError`, but not that this does not allow output to be captured directly in PowerShell.
Method 3. Invoke-Expression Cmdlet
This camdlet allows for dynamic command execution but is less commonly used due to the security concerns. Invoke-Expression executes arbitrary strings as code, which can be a security risk if the string is not properly sanitized. If you want to try run an .exe file using the Invoke-Expression camdlet in PowerShell, follow the next steps:
Step 1. After open PowerShell, create a string that contains the full command for executing the .exe file, including any parameters. For example:
$command = '"C:\Program Files\MyApp\MyApp.exe" -arg1 value1 -arg2 value2'
Step 2. Pass the constructed string to Invoke-Expression:
Invoke-Expression $command
Example Command:
Here’s a complete example where we run an executable with parameters:
$command = '"C:\Program Files\Automated QA\TestExecute 8\Bin\TestExecute.exe"
C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode'
Invoke-Expression $command
Additional Tips
- You can change directories using `cd` and then run the executable directly:
cd "C:\Path\To\Directory"
.\YourFile.exe
- You can also specify parameters when running executable. For example:
Start-Process -FilePath "C:\Path\To\YourFile.exe" -ArgumentList "-param1 value1"
The above methods, you can efficiently manage and execute.exe files directly from PowerShell, enhancing your work flow and automation capabilities.
Bonus: AirDroid Remote Support
AirDroid Remote Support is an excellent choice for anyone seeking a reliable and user-friendly solution for remote assistance. With its intuitive features, including real-time screen sharing, voice communication, and file transfer capabilities, AirDroid remote support stands out as a versatile tool for both personal and business use.
Whether your are a developer, system administrator, or simply someone who assists friends and family with tech issues, the remote support software assistance straightforward and effective.
Conclusion
PowerShell not only simplifies the execution of .exe files but also empowers user to automate and manage their tasks more efficiently. By mastering these methods, IT professionals can enhance their productivity and effectively handle software management in various environments.
Leave a Reply.