README.md

December 4, 2022 ยท View on GitHub

Find Server Uptime

Description

This will find how long the computer has been running. I have tried it on three different computers, each one accurately displays the uptime. Please vote and leave comments. Thank you

More Info

Uses FileSystemObject and reads the DateLastModified atribune from the pagefile.sys.

Returns Uptime

Submitted On
ByRob R
LevelIntermediate
User Rating4.8 (43 globes from 9 users)
CompatibilityASP (Active Server Pages)
CategoryMiscellaneous
WorldASP / VbScript
Archive File

Source Code

<%
 Dim PageFileModDate, UptimeInSeconds, TotalUptime
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set PageFile = fso.GetFile ("C:\pagefile.sys")
 'get the page
 PageFileModDate = PageFile.DateLastModified
 'Finds how many seconds between now and the pagefile mod date
 UptimeInSeconds = DateDiff("S", PageFileModDate, Now())
 'Calls a function to format the seconds
 FormatSeconds (UptimeInSeconds)
 'writes the Uptime to the browser
 Response.write "Total uptime:<br><br>"
 Response.write TotalUptime
 'format function
 Function FormatSeconds(TotalSeconds)
 Seconds = TotalSeconds Mod 60
 Minutes = TotalSeconds \ 60 Mod 60
 Hours = TotalSeconds \ 3600 Mod 24
 Days = TotalSeconds \ 3600 \ 24
 TotalUptime = Days & " days " & Hours & " hours " & Minutes & " minutes " & Seconds & " seconds"
 End Function
 'dispose of the objects
 Set PageFile = Nothing
 Set fso = Nothing
%>