Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if processis running

Status
Not open for further replies.

alanwes

Programmer
Aug 5, 2008
5
GB
Im trying to check if a process is running but get an error when checking which i dont want the users of my script to see, anyone know how i do this correctly ?

if ((Get-Process 'WinWord') -eq $False){
Write-Host "Please close all instances of Microsoft Word before running this report."
exit
}

Thanks
 
Solved....

$wordrunning = (Get-Process 'WinWord' -ea SilentlyContinue)
if ( $wordrunning -eq ""){
Write-Host "Please close all instances of Microsoft Word."
exit
}
else
{
}
 
Try this one-liner. I love one-liners.

Code:
if (Get-Process 'WinWord' -ea SilentlyContinue) {write-host "running"}

HTH,

Jonathan Almquist
 
stop-process -processname winword

means you don't need to ask them to close the app :)
 
if((get-process "notepad" -ea SilentlyContinue) -eq $Null){ echo "Not Running" }else{ echo "Running" }

This should cover it. I've tested it and it works fine. You can put anything in the braces, or you can use this in a while loop to wait for a process to die.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top