Question

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

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top