Cmd/PowerShell/SQL server: Is there any way to see how long a windows service has been running?

荒凉一梦 提交于 2019-12-09 23:58:04

问题


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


来源:https://stackoverflow.com/questions/26408395/cmd-powershell-sql-server-is-there-any-way-to-see-how-long-a-windows-service-ha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!