Reputation: 27
I need help creating a powershell script that looks for a running process and if its not there launch it. Right now, the VB script I have looks for the process and launches, but because of Windows 7 Fast User Switching, that process can be running in any user session and it makes the script think its running in the current user session. Any help or pointers is greatly appreciated!
Upvotes: 2
Views: 3977
Reputation: 8650
Relatively simple code:
if (
Get-WmiObject -Class Win32_Process -Filter "Name = 'explorer.exe'" |
where {
$_.GetOwner().User -eq $env:USERNAME
}
) {
"explorer is running for $env:username"
}
This should ignore this process running for any other user than current. Just replace explorer.exe with actual process and change logic to match your need.
Upvotes: 3