문제

We have a program that installs itself as a service windows, runs for about 5 minutes and then uninstalls.

Sometimes (due to bugs) it fails to uninstall and the service processes are left hanging.

I'm trying to write a powershell script that will remove all processes running more than an hour. Now I cant find anything that could tell me how long the service is running (when it was installed).

Is there a way to find out when service was installed or how long it is running?

Thank you, Vitaly

도움이 되었습니까?

해결책

You can use Get-Process to see when the service process was started, like so:

Get-Process | select name, starttime

This will get the processid based on the service name:

$myservice = "Spooler"

$starttime = Get-Process -id ((Get-WmiObject win32_service -Filter "name=`'$myService`'").ProcessID) | select StartTime

$timerunning = (get-date).Subtract($starttime.StartTime)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top