草庐IT

windows - 命令/PowerShell/SQL 服务器 : Is there any way to see how long a windows service has been running?

coder 2024-06-19 原文

所以我设法通过 sc query "ServiceName"| 来检查服务是否正在运行 |找到“RUNNING”或net start |找到“服务名称”,或在 SQL Server 中使用 xp_servicecontrol。有没有办法查看服务的正常运行时间?如何查看服务的正常运行时间?

最佳答案

只要您的服务有自己的进程名称,这就应该有效。

PowerShell_v4> (Get-Process lync).StartTime

Friday, October 17, 2014 11:46:04

如果您在 svchost.exe 下运行,我认为您需要从事件日志中获取它。

PowerShell_v4> (Get-WinEvent -LogName System | ? Message -match 'DHCPv6 client service is started' | select -First 1).TimeCreated

Friday, October 17, 2014 10:10:56

对于正常运行时间,只需计算时间差异。

$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

关于windows - 命令/PowerShell/SQL 服务器 : Is there any way to see how long a windows service has been running?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26408395/

有关windows - 命令/PowerShell/SQL 服务器 : Is there any way to see how long a windows service has been running?的更多相关文章

随机推荐