So I managed to check if a sevice is running with sc query "ServiceName" | find "RUNNING" or net start | find "Service Name", or in SQL Server using xp_servicecontrol. Is there any way to see the uptime of a service? How can I see the uptime of a service?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
As long as your service has it's own process name, this should work.
PowerShell_v4> (Get-Process lync).StartTime
Friday, October 17, 2014 11:46:04
If you're running under svchost.exe, i think you need to grab that from Event Log.
PowerShell_v4> (Get-WinEvent -LogName System | ? Message -match 'DHCPv6 client service is started' | select -First 1).TimeCreated
Friday, October 17, 2014 10:10:56
For Uptime, just compute time diff.
$Start = (Get-Process Outlook).StartTime
$Now = Get-Date
$Now - $Start | Format-Table Days, Hours, Minutes, Seconds -AutoSize
Days Hours Minutes Seconds
---- ----- ------- -------
0 0 2 8
or as a one-liner:
(Get-Date) - (Get-Process Outlook).StartTime | Format-Table Days, Hours, Minutes, Seconds -AutoSize
Days Hours Minutes Seconds
---- ----- ------- -------
0 0 2 8