Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Convert UINT64 to usable string in ASP (Win32_PerfRawData_PerfOS_System - SystemUpTime)

Posted on 2008-10-29
2
670 Views
Last Modified: 2012-03-15
I was using Win32_PerfFormattedData_PerfOS_System - SystemUpTime to determing how long a server had been online, unfortunately that doesn't exist in Server 2000.  So, I decided to use Win32_PerfRawData_PerfOS_System.  However, the number is like 128697836904361421 and I have no idea how to convert that to anything useful.  I did discover it's uINT64, but that doesn't help me any...

How do I make this useful? What kind of math do I need to convert it to seconds?
0
Comment
Question by:Cerixus
2 Comments
 
LVL 14

Accepted Solution

by:
rejoinder earned 500 total points
ID: 22835614
You can try this code to see if it fits your needs.  

I check the LastBootTime of the Win32_OperatingSystem object to get the date.  From there, I check the OS to see if it is running Windows 2000.  If so, the script uses the function "ConvWMI2VBS" to convert the date while other systems are converted using the function "WMIDateStringToDate"
'http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q__23859663.html
 
strSrv = "SERVERNAME"
set objSvc = GetObject("winmgmts:{impersonationLevel=impersonate}//" & StrSrv & "/root/cimv2")
set objRet=objSvc.InstancesOf("win32_OperatingSystem")
for each item in objRet
    if item.LastBootUpTime <> "" then
        if InStr(item.caption, "2000") then
            LastBootTime = ConvWMI2VBS(item.LastBootUpTime)
        else
            LastBootTime = WMIDateStringToDate(item.LastBootUpTime)
        end if
    else
        LastBootTime = "The script was unable to check the last known boot time."
    end if
next
 
wscript.echo LastBootTime
 
'******************************
'* Convert Date Function *
'******************************
 
Function ConvWMI2VBS(strDate)
    'will return mm/dd/yyyy
    Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
    objSWbemDateTime.Value = strDate
    ConvWMI2VBS = objSWbemDateTime.GetVarDate(False)
End Function
 
Function WMIDateStringToDate(dtmBootup)
    'will return mm/dd/yyyy
    WMIDateStringToDate = CDate(Mid(dtmBootup, 7, 2) & "/" & Mid(dtmBootup, 5, 2) & "/" & Left(dtmBootup, 4) & " " & Mid (dtmBootup, 9, 2) & ":" & Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, 13, 2))
End Function

Open in new window

0
 
LVL 1

Author Closing Comment

by:Cerixus
ID: 31511392
Other than the fact that the month/day were switched on the 2003 servers, this worked perfectly!  :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VbScript to countdown to New Year's Day 6 64
VBA & VBSCRIPT: re-adapt log file 13 33
Everything left of comma in excel 4 44
IIS components 2 14
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question