Jump to content

System Uptime on Windows10


ces1a
 Share

Recommended Posts

I was looking for a way to find out how long my PC had been running a few weeks ago and had trouble finding something that satisfied my needs,  I found a Visual Basic Script that worked but found it too long. But searching trough AutoIt WINAPI help found that it really was as simple as the following little script.

#include <WinAPISys.au3>
#include <WinAPIMisc.au3>

Local $Uptime = _WinAPI_StrFromTimeInterval(_WinAPI_GetTickCount())
MsgBox(0, '', "PC Uptime ==> " & $UpTime)

Hope it helps...

Link to comment
Share on other sites

Welcome ces1a,

That is a very quick and useful way to get the uptime, yes.  I hadn't come across that method before; however, reading the verbiage on the _GetTick function from the help file, this method will be unreliable if the machine is "up" for longer than ~48+ days.  The help article also suggests using probing the system uptime counter from performance data...another way I've not done (or seen). 

Sure, the likely hood of a Windows machine being online that long is pretty low (if it is patched monthly), but it might be worth while thinking about these limitations and consider how you would address those limitations if necessary.


An alternative approach, which I have seen and used, is to collect the system boot time and calculate the duration from "now".  Here's an old(er) link to some examples. ;) https://www.autoitscript.com/forum/topic/110300-system-uptime/#comment-774837

I'm not trying to critique too harshly...I just noticed this is your first post and wanted to expand your knowledge in case you weren't aware or didn't think about it.  Once again welcome.

 

edit: to be fair...I have not tested those examples on Win 10 or verified they work with the latest ver(s) of AutoIt.  I just wanted to provide some more code for you to check out.

Edited by spudw2k
Link to comment
Share on other sites

  • 2 weeks later...

You are right about the limitations of the method but if you modify it as follows it works.

#include <WinAPISys.au3>
#include <WinAPIMisc.au3>

Local $Uptime = _WinAPI_StrFromTimeInterval(_WinAPI_GetTickCount64())
MsgBox(0, '', "PC Uptime ==> " & $UpTime)

 

The only difference is the line: 

   Local $Uptime = _WinAPI_StrFromTimeInterval(_WinAPI_GetTickCount())

Is changed to:

    Local $Uptime = _WinAPI_StrFromTimeInterval(_WinAPI_GetTickCount64())

Thanks for your input.

Link to comment
Share on other sites

  • 5 weeks later...

There is a really easy command for this.

In command prompt, type "net statistics workstation" and press enter. You will see "Statistics since <DatePCStarted> <TimePCStarted>" at the top which essentially tells you when you started your computer.

 

btw, you can just press windows key + r (run dialog) and type "cmd /k net statistics workstation" for the same effect. the /k flag tells cmd to remain open and accept new commands once the command is processed. Optionally, you can do "cmd /c pause | net statistics workstation" instead if you don't want cmd to accept new commands but still remain open. Note Pause must be first entry or it won't actually pause.

 

 

Link to comment
Share on other sites

  • 3 months later...

Thanks for the info, BetaLeaf, but what I needed in my case is to run a program when my computer starts.

The program has to wait 3 minutes from the time the laptop started to run two programs so as not to slow Windows startup in any way.

Getting the System Uptime had to take place automatically.  This way when the computer has been running close to three minutes my script runs two of my other programs.

 

Link to comment
Share on other sites

Put a 3 minute delay at the start of the script you're running, that way no matter when it starts running the rest of the script won't do anything until 3 minutes later.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...