Print uptime (Perl)

This code can be found in Chapter 2 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# This code prints system uptime for a host.
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------
use Win32::OLE qw(in);
$Win32::OLE::Warn = 3;
use Win32::OLE::Variant;

# ------ SCRIPT CONFIGURATION ------
$strComputer = '.'; # e.g. rallen-srv01
# ------ END CONFIGURATION ---------
$objWMIDateTime = Win32::OLE->new('WbemScripting.SWbemDateTime');
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colOS = $objWMI->InstancesOf('Win32_OperatingSystem');
foreach my $objOS (in $colOS) {
    $objWMIDateTime->{Value} = $objOS->LastBootUpTime;
    print 'System Up Time: ' . $objWMIDateTime->GetVarDate, "\n";
}

This code has been viewed 1686 times.

New from the creators of TechTasks.com: StatSheet.com