【问题标题】:Cmd/PowerShell/SQL server: Is there any way to see how long a windows service has been running?Cmd/PowerShell/SQL server:有什么方法可以查看 Windows 服务运行了多长时间?
【发布时间】:2014-10-16 15:35:00
【问题描述】:

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

【问题讨论】:

    标签: windows service cmd uptime


    【解决方案1】:

    只要您的服务有自己的进程名称,这应该可以工作。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多