Windows Uptime & Installation Information Example

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Windows Uptime & Installation Information Example

Post by Rain » Tue Jun 25, 2013 2:57 pm

A script to illustrate the power of Macro Scheduler and VBScript.

This example retrieves the following information:
1. Date and time Windows was installed
2. How long it's been since Windows was installed in Days:Hours:Minutes:Seconds
3. How long it's been since Windows was Started/Rebooted in Days:Hours:Minutes:Seconds

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Windows Uptime & Installation Information'
  ClientHeight = 132
  ClientWidth = 382
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 3
    Height = 13
  end
  object Label2: TLabel
    Left = 8
    Top = 32
    Width = 3
    Height = 13
  end
  object Label3: TLabel
    Left = 8
    Top = 56
    Width = 3
    Height = 13
  end
  object MSButton1: tMSButton
    Left = 304
    Top = 104
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit1: TEdit
    Left = 8
    Top = 8
    Width = 369
    Height = 21
    BevelInner = bvNone
    BevelOuter = bvNone
    BorderStyle = bsNone
    Color = clBtnFace
    ReadOnly = True
    TabOrder = 1
    Text = 'Edit1'
  end
  object Edit2: TEdit
    Left = 8
    Top = 40
    Width = 369
    Height = 21
    BevelInner = bvNone
    BevelOuter = bvNone
    BorderStyle = bsNone
    Color = clBtnFace
    ReadOnly = True
    TabOrder = 2
    Text = 'Edit2'
  end
  object Edit3: TEdit
    Left = 8
    Top = 72
    Width = 369
    Height = 21
    BevelInner = bvNone
    BevelOuter = bvNone
    BorderStyle = bsNone
    Color = clBtnFace
    ReadOnly = True
    TabOrder = 3
    Text = 'Edit3'
  end
end
EndDialog>Dialog1


AddDialogHandler>Dialog1,MSButton1,OnClick,ExitScript
AddDialogHandler>Dialog1,,OnClose,ExitScript

//Get Windows install date
RegistryReadKey>HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows NT\CurrentVersion,InstallDate,UnixTime

//Convert install date from Unix time to readable date and time (This example requires "s" seconds)
/*
Intervals:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second
*/
VBEval>DateAdd("s", "%UnixTime%", "01/01/1970 00:00:00"),Install_Date_Res

//Format date and time from 2/1/2013 5:13:31 PM to Friday, February 01, 2013  5:13:31 PM for example
/*
format:
A value that specifies the date/time format to use Can take the following values:
0 = General Date - Default. Returns date: mm/dd/yy and time if specified: hh:mm:ss PM/AM.
1 = Long Date - Returns date: weekday, monthname, year
2 = Short Date - Returns date: mm/dd/yy
3 = Long Time - Returns time: hh:mm:ss PM/AM
4 = Short Time - Return time: hh:mm
*/
VBEval>FormatDateTime("%Install_Date_Res%", 1),InstallDateRes
VBEval>FormatDateTime("%Install_Date_Res%", 3),InstallTimeRes


SetDialogProperty>Dialog1,Edit1,Text,Windows Install Date: %InstallDateRes%  %InstallTimeRes%
Show>Dialog1
Label>Loop
  //Calculate how long it has been since Windows was installed (This example requires "s" seconds)
  /*
  format:
  A value that specifies the date/time format to use Can take the following values:
  0 = General Date - Default. Returns date: mm/dd/yy and time if specified: hh:mm:ss PM/AM.
  1 = Long Date - Returns date: weekday, monthname, year
  2 = Short Date - Returns date: mm/dd/yy
  3 = Long Time - Returns time: hh:mm:ss PM/AM
  4 = Short Time - Return time: hh:mm
  */
  GetDate>TheDateNow
  GetTime>TheTimeNow
  VBEval>DateDiff("s", "%Install_Date_Res%", "%TheDateNow% %TheTimeNow%"),ElapsedSeconds
  Let>DaysElapsed={%ElapsedSeconds% DIV 86400}
  Let>ElapsedSeconds={%ElapsedSeconds% MOD 86400}
  Let>HoursElapsed={%ElapsedSeconds% DIV 3600}
  Let>ElapsedSeconds={%ElapsedSeconds% MOD 3600}
  Let>MinutesElapsed={%ElapsedSeconds% DIV 60}
  Let>SecondsElapsed={%ElapsedSeconds% MOD 60}
  SetDialogProperty>Dialog1,Edit2,Text,Windows was Installed %DaysElapsed% Days %HoursElapsed% Hours %MinutesElapsed% Minutes %SecondsElapsed% Seconds ago
  
  //Calculate how long it has been since Windows was started/rebooted
  LibFunc>kernel32.dll,GetTickCount,MillisecondsTickCount
  Let>SecondsTickCount={%MillisecondsTickCount% DIV 1000}
  Let>ElapsedSeconds={Round(%SecondsTickCount%)}
  Let>DaysElapsed={%ElapsedSeconds% DIV 86400}
  Let>ElapsedSeconds={%ElapsedSeconds% MOD 86400}
  Let>HoursElapsed={%ElapsedSeconds% DIV 3600}
  Let>ElapsedSeconds={%ElapsedSeconds% MOD 3600}
  Let>MinutesElapsed={%ElapsedSeconds% DIV 60}
  Let>SecondsElapsed={%ElapsedSeconds% MOD 60}
  SetDialogProperty>Dialog1,Edit3,Text,%DaysElapsed% Days %HoursElapsed% Hours %MinutesElapsed% Minutes %SecondsElapsed% Seconds Since your system was started

  Wait>.5
Goto>Loop

SRT>ExitScript
  Exit>1
END>ExitScript


User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Wed Jun 26, 2013 3:23 am

Hi Rain,

That's a nice script, my machine has been up for over 7 days, maybe time for a reboot.

I like the fact that you reference the original install time as well as how long it has been.
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts