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
David PhelopsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ 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.

BFN,

fp.
Q-28264440.xls
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

uf-Uptime.frm
0
David PhelopsAuthor Commented:
Very helpful, clear and specific answer.
most appreciated.
Cheers
David
0
[ 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 ]
0
David PhelopsAuthor Commented:
oh, yes, thanks - that is useful to know too, (Evil and Dilbertian) :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.