如何在 Windows 中获得系统正常运行时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11606774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:42:41  来源:igfitidea点击:

How to get the system uptime in Windows?

windows

提问by Anil Kumar C

I am using windows 7 and xp. I want to know the uptime of the system.

我正在使用 Windows 7 和 xp。我想知道系统的正常运行时间。

What is the command / procedure for getting the uptime?

获取正常运行时间的命令/程序是什么?

回答by Anil Kumar C

Following are eight ways to find the Uptimein Windows OS.

以下是在 Windows 操作系统中查找正常运行时间的八种方法。

1: By using the Task Manager

1:使用任务管理器

In Windows Vista and Windows Server 2008, the Task Manager has been beefed up to show additional information about the system. One of these pieces of info is the server's running time.

在 Windows Vista 和 Windows Server 2008 中,任务管理器得到了加强,可以显示有关系统的附加信息。这些信息之一是服务器的运行时间。

  1. Right-click on the Taskbar, and click Task Manager. You can also click CTRL+SHIFT+ESCto get to the Task Manager.
  2. In Task Manager, select the Performance tab.
  3. The current system uptime is shown under System or Performance ⇒ CPU for Win 8/10.

    "Up Time" field in Task Manager

  1. 右键单击任务栏,然后单击任务管理器。您也可以单击CTRL+ SHIFT+ESC进入任务管理器。
  2. 在任务管理器中,选择性能选项卡。
  3. 当前系统正常运行时间显示在系统或性能 ⇒ Win 8/10 的 CPU 下。

    任务管理器中的“正常运行时间”字段

2: By using the System Information Utility

2:通过使用系统信息实用程序

The systeminfocommand line utility checks and displays various system statistics such as installation date, installed hotfixes and more. Open a Command Prompt and type the following command:

systeminfo命令行实用程序检查和显示各种系统统计数据,如安装日期,安装的修补程序等等。打开命令提示符并键入以下命令:

systeminfo

You can also narrow down the results to just the line you need:

您还可以将结果缩小到您需要的行:

systeminfo | find "System Boot Time:"

enter image description here

在此处输入图片说明

3: By using the Uptime Utility

3:通过使用正常运行时间实用程序

Microsoft have published a tool called Uptime.exe. It is a simple command line tool that analyses the computer's reliability and availability information. It can work locally or remotely. In its simple form, the tool will display the current system uptime. An advanced option allows you to access more detailed information such as shutdown, reboots, operating system crashes, and Service Pack installation.

Microsoft 发布了一个名为 Uptime.exe 的工具。它是一个简单的命令行工具,用于分析计算机的可靠性和可用性信息。它可以在本地或远程工作。该工具以简单的形式显示当前系统的正常运行时间。高级选项允许您访问更详细的信息,例如关机、重新启动、操作系统崩溃和 Service Pack 安装。

Read the following KB for more info and for the download links:

阅读以下 KB 以获取更多信息和下载链接:

To use it, follow these steps:

要使用它,请按照下列步骤操作:

  1. Download uptime.exe from the above link, and save it to a folder, preferably in one that's in the system's path (such as SYSTEM32).
  2. Open an elevated Command Prompt window. To open an elevated Command Prompt, click Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator. You can also type CMD in the search box of the Start menu, and when you see the Command Prompt icon click on it to select it, hold CTRL+SHIFTand press ENTER.
  3. Navigate to where you've placed the uptime.exe utility.
  4. Run the uptime.exeutility. You can add a /? to the command in order to get more options. enter image description here
  1. 从上面的链接下载 uptime.exe,并将其保存到一个文件夹中,最好是在系统路径中的一个文件夹中(例如 SYSTEM32)。
  2. 打开提升的命令提示符窗口。要打开提升的命令提示符,请依次单击开始、所有程序、附件、右键单击命令提示符,然后单击以管理员身份运行。您也可以在开始菜单的搜索框中键入 CMD,当您看到命令提示符图标时单击它以将其选中,按住 CTRL+SHIFT并按ENTER
  3. 导航到放置 uptime.exe 实用程序的位置。
  4. 运行该uptime.exe实用程序。您可以添加 /? 到命令以获得更多选项。 在此处输入图片说明

It does not offer many command line parameters:

它不提供许多命令行参数:

C:\uptimefromcodeplex\> uptime /?
usage: Uptime [-V]
    -V   display version

C:\uptimefromcodeplex\> uptime -V
version 1.1.0

3.1: By using the old Uptime Utility

3.1:通过使用旧的正常运行时间实用程序

There is an older version of the "uptime.exe" utility. This has the advantage of NOT needing .NET. (It also has a lot more features beyond simple uptime.)

有一个旧版本的“uptime.exe”实用程序。这具有不需要 .NET 的优点。(除了简单的正常运行时间之外,它还具有更多功能。)

Download link: Windows NT 4.0 Server Uptime Tool (uptime.exe) (final x86)

下载链接:Windows NT 4.0 Server Uptime Tool (uptime.exe)(最终版 x86)

C:\uptimev100download>uptime.exe /?

UPTIME, Version 1.00
(C) Copyright 1999, Microsoft Corporation

Uptime [server] [/s ] [/a] [/d:mm/dd/yyyy | /p:n] [/heartbeat] [/? | /help]
        server          Name or IP address of remote server to process.
        /s              Display key system events and statistics.
        /a              Display application failure events (assumes /s).
        /d:             Only calculate for events after mm/dd/yyyy.
        /p:             Only calculate for events in the previous n days.
        /heartbeat      Turn on/off the system's heartbeat
        /?              Basic usage.
        /help           Additional usage information.

4: By using the NET STATISTICS Utility

4:通过使用 NET STATISTICS 实用程序

Another easy method, if you can remember it, is to use the approximate information found in the statistics displayed by the NET STATISTICS command. Open a Command Prompt and type the following command:

如果您还记得的话,另一种简单的方法是使用 NET STATISTICS 命令显示的统计信息中的近似信息。打开命令提示符并键入以下命令:

net statistics workstation

The statistics should tell you how long it's been running, although in some cases this information is not as accurate as other methods.

统计信息应该告诉您它运行了多长时间,尽管在某些情况下,此信息不如其他方法准确。

enter image description here

在此处输入图片说明

5: By Using the Event Viewer

5:使用事件查看器

Probably the most accurate of them all, but it does require some clicking. It does not display an exact day or hour count since the last reboot, but it will display important information regarding why the computer was rebooted and when it did so. We need to look at Event ID 6005, which is an event that tells us that the computer has just finished booting, but you should be aware of the fact that there are virtually hundreds if not thousands of other event types that you could potentially learn from.

可能是其中最准确的,但它确实需要点击一下。它不会显示自上次重新启动以来的确切天数或小时数,但会显示有关计算机重新启动的原因和时间的重要信息。我们需要查看事件 ID 6005,这是一个告诉我们计算机刚刚完成启动的事件,但您应该意识到事实上有数百甚至数千种其他事件类型可供您学习.

Note: BTW, the 6006 Event ID is what tells us when the server has gone down, so if there's much time difference between the 6006 and 6005 events, the server was down for a long time.

注意:顺便说一句,6006 事件 ID 是告诉我们服务器何时停机的信息,因此如果 6006 和 6005 事件之间的时间差很大,则服务器停机很长时间。

Note: You can also open the Event Viewer by typing eventvwr.msc in the Run command, and you might as well use the shortcut found in the Administrative tools folder.

注意:您还可以通过在运行命令中键入 eventvwr.msc 来打开事件查看器,您也可以使用在管理工具文件夹中找到的快捷方式。

  1. Click on Event Viewer (Local) in the left navigation pane.
  2. In the middle pane, click on the Information event type, and scroll down till you see Event ID 6005. Double-click the 6005 Event ID, or right-click it and select View All Instances of This Event.
  3. A list of all instances of the 6005 Event ID will be displayed. You can examine this list, look at the dates and times of each reboot event, and so on.
  4. Open Server Manager tool by right-clicking the Computer icon on the start menu (or on the Desktop if you have it enabled) and select Manage. Navigate to the Event Viewer.
  1. 单击左侧导航窗格中的事件查看器(本地)。
  2. 在中间窗格中,单击信息事件类型,然后向下滚动直到看到事件 ID 6005。双击 6005 事件 ID,或右键单击它并选择查看此事件的所有实例。
  3. 将显示 6005 事件 ID 的所有实例的列表。您可以检查此列表,查看每个重新启动事件的日期和时间,等等。
  4. 通过右键单击开始菜单上的计算机图标(或桌面上,如果已启用),打开服务器管理器工具,然后选择管理。导航到事件查看器。

enter image description here

在此处输入图片说明

5.1: Eventlog via PowerShell

5.1: 通过 PowerShell 的事件日志

Get-WinEvent -ProviderName eventlog | Where-Object {$_.Id -eq 6005 -or $_.Id -eq 6006}

6: Programmatically, by using GetTickCount64

6:以编程方式,使用GetTickCount64

GetTickCount64 retrieves the number of milliseconds that have elapsed since the system was started.

GetTickCount64 检索自系统启动以来经过的毫秒数。

7: By using WMI

7:通过使用 WMI

wmic os get lastbootuptime

8: The new uptime.exe for Windows XP and up

8:适用于 Windows XP 及更高版本的新 uptime.exe

Like the tool from Microsoft, but compatible with all operating systems up to and including Windows 10 and Windows Server 2016, this uptime utilitydoes not require an elevated command prompt and offers an option to show the uptime in both DD:HH:MM:SS and in human-readable formats (when executed with the -hcommand-line parameter).

与 Microsoft 的工具类似,但与包括 Windows 10 和 Windows Server 2016 在内的所有操作系统兼容,此正常运行时间实用程序不需要提升的命令提示符,并提供一个选项来显示 DD:HH:MM:SS 中的正常运行时间和人类可读的格式(当使用-h命令行参数执行时)。

Additionally, this version of uptime.exewill run and show the system uptime even when launched normally from within an explorer.exe session (i.e. not via the command line) and pause for the uptime to be read:

此外,uptime.exe即使从 explorer.exe 会话中正常启动(即不通过命令行),此版本也会运行并显示系统正常运行时间,并暂停以读取正常运行时间:

enter image description here

在此处输入图片说明

and when executed as uptime -h:

当执行为uptime -h

enter image description here

在此处输入图片说明

回答by Joey

I use this little PowerShell snippet:

我使用这个小的 PowerShell 片段:

function Get-SystemUptime {
    $operatingSystem = Get-WmiObject Win32_OperatingSystem
    "$((Get-Date) - ([Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)))"
}

which then yields something like the following:

然后产生如下内容:

PS> Get-SystemUptime
6.20:40:40.2625526

回答by Praveen Govind

Two ways to do that..

有两种方法可以做到这一点..

Option 1:

选项1:

1.  Go to "Start" -> "Run".

2.  Write "CMD" and press on "Enter" key.

3.  Write the command "net statistics server" and press on "Enter" key.

4.  The line that start with "Statistics since …" provides the time that the server was up from.


  The command "net stats srv" can be use instead.

Option 2:

选项 2:

Uptime.exe Tool Allows You to Estimate Server Availability with Windows NT 4.0 SP4 or Higher

Uptime.exe 工具允许您使用 Windows NT 4.0 SP4 或更高版本估计服务器可用性

http://support.microsoft.com/kb/232243

http://support.microsoft.com/kb/232243

Hope it helped you!!

希望对你有帮助!!