• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1099
  • Last Modified:

Determine How Long Since Last Boot

There is always someone in the office who will notever refresh, reboot, switch off, or restart his / her pc.

Is there a method to determine, from within excel vba, how long windows has been running?

Thereby enabling a message box to be displayed recommending that the user reboot his machine if it has been running for a long time?

Thanks you very much
David Phelops
David Phelops
  • 3
  • 2
1 Solution
[ fanpages ]IT Services ConsultantCommented:
Hi David,

Yes, there is!  You can use "GetTickCount" ("The return value is the number of milliseconds that have elapsed since the system was started"):

(Private|Public) Declare Function GetTickCount Lib "kernel32.dll" () As Long

Here is a previous question with Visual Basic (note: not "for Applications") code:

"Windows up time..."
[ http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20075455.html ]

The two external links to PlanetSourceCode.com are now not valid, but the use of "GetTickCount" is still available to you (in MS-Excel/VBA).

Further information:
[ http://msdn.microsoft.com/en-us/library/windows/desktop/ms724408(v=vs.85).aspx ]

I have attached a sample workbook that displays the "GetTickCount" value in cell [B1], & the number of hours:minutes:seconds.milliseconds of this same value in cell [B2].

Just re-calculate (press [F9]) the worksheet to update the two cells.


David PhelopsAuthor Commented:
Thanks very much fanpages - really specific and helpful information - exactly what I needed.
This is how I have used it:

VB userform attached for your pleasure!

Run as follows:
Sub Uptime()

'This routine displays a userform, if his/her PC has been running for 4 days, to recommend that it is re-booted.
'Note: GetTickCount system function shown in milliseconds

If GetTickCount > 691200000 Then uf_Uptime.Show

End Sub

Open in new window

David PhelopsAuthor Commented:
Very helpful, clear and specific answer.
most appreciated.
[ fanpages ]IT Services ConsultantCommented:
You're very welcome.

Thanks for the attachment.

Good luck with convincing your users to not ignore the message!

Talking of which, this (currently active) question thread may interest you (just for thoughts on enhancing your approach):

[ http://www.experts-exchange.com/Q_28263135.html ]
David PhelopsAuthor Commented:
oh, yes, thanks - that is useful to know too, (Evil and Dilbertian) :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now