Cmd / PowerShell / SQL服务器:有什么方法可以看到一个Windows服务已经运行多长时间? [英] Cmd/PowerShell/SQL server: Is there any way to see how long a windows service has been running?
问题描述
所以我设法检查一个服务是否正在运行sc查询ServiceName|找到RUNNING或net start |查找服务名称,或在SQL Server中使用xp_servicecontrol。有任何方法来查看服务的正常运行时间吗?如何查看服务的正常运行时间?
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?
推荐答案
只要您的服务有自己的进程名称,这应该可以工作。
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
b $ b
如果你运行在svchost.exe下,我想你需要从事件日志中获取。
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
对于Uptime,只需计算时间差异。
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
或作为单行:
(Get-Date) - (Get-Process Outlook).StartTime | Format-Table Days, Hours, Minutes, Seconds -AutoSize
Days Hours Minutes Seconds
---- ----- ------- -------
0 0 2 8
这篇关于Cmd / PowerShell / SQL服务器:有什么方法可以看到一个Windows服务已经运行多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!