PowerShell Script to Restrict Application to a Single Instance

Here is a simple Powershell code that checks if a specified process is already running and launches second instance of the application if it’s not already running.

$process = "mspaint"
$ret = Get-Process -Name $process -ErrorAction SilentlyContinue 
if ($ret) {
    Write-Host "INFO: $process already running, skipping start of another instance of the same process"
} else {
    Write-Host "VERBOSE: Starting $process now"
    Invoke-Item  "$process.exe" 



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.