Thursday, 16 April 2015

Run Exe from bat file

Create a .bat file. ex: MyApp.bat
Call powershell script from batch file.
@Set exePath="C:\My.exe"
Echo "Call PS1"
PowerShell.exe Set-ExecutionPolicy RemoteSigned; "C:\MyScript.PS1" -exePath %exePath%
Echo "End PS1"
PAUSE
view raw gistfile1.ps1 hosted with ❤ by GitHub


Now create a PS1 script ex" MyScript.PS1

Calling exe from Powershell
Param
(
[string]$exePath = $null
)
write-host “Calling exe”
$startTime = Get-Date
Write-Host "Start time " + $startTime.ToString("u")
$exePath = $exePath
& $exePath
$endTime = Get-Date
Write-Host "End time " + $endTime.ToString("u")
write-host “End exe”
view raw gistfile1.ps1 hosted with ❤ by GitHub