Jump to content

[Solved] Readable time format


UEZ
 Share

Recommended Posts

Can somebody help to convert the "InstalledOn" output format to a readable format?

$system = "Localhost"
$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $system & "\root\cimv2")

Test($system)

Func Test($srv)
    $colItems = $objWMIService.ExecQuery("Select HotFixID, InstalledOn from Win32_QuickFixEngineering Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'", "WQL", 0x30)
    For $objItem In $colItems
        ConsoleWrite("Hot Fix ID: " & $objItem.HotFixID & " ; " & "Installed on: " & $objItem.InstalledOn & @CRLF)
    Next
EndFunc

When you start this script on Vista then the output format is like this:

...

Hot Fix ID: KB929550 ; Installed on: 01c918a0035385dc

Hot Fix ID: KB929685 ; Installed on: 01c81a2724ae7b96

Hot Fix ID: KB929731 ; Installed on: 01c918a0035385dc

...

You can see that the "Installed on" format is a long hex value.

I searched in the web but found only C++ examples:

FILETIME installFileTime;

SYSTEMTIME installSysTime;

swscanf_s(InstalledOn,L"%08x%08x",

&installFileTime.dwHighDateTime, &installFileTime.dwLowDateTime);

FileTimeToSystemTime( &installFileTime, &installSysTime);

StringCchPrintf(InstalledOn,wcslen(InstalledOn),L"%d/%d/%d",

installSysTime.wMonth,installSysTime.wDay,installSysTime.wYear);

But I've no C/C++ knowledge! Can somebody translate it to AutoIt code format?

Thanks,

UEZ

:)

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Can somebody help to convert the "InstalledOn" output format to a readable format?

$system = "Localhost"
$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $system & "\root\cimv2")

Test($system)

Func Test($srv)
    $colItems = $objWMIService.ExecQuery("Select HotFixID, InstalledOn from Win32_QuickFixEngineering Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'", "WQL", 0x30)
    For $objItem In $colItems
        ConsoleWrite("Hot Fix ID: " & $objItem.HotFixID & " ; " & "Installed on: " & $objItem.InstalledOn & @CRLF)
    Next
EndFunc

When you start this script on Vista then the output format is like this:

...

Hot Fix ID: KB929550 ; Installed on: 01c918a0035385dc

Hot Fix ID: KB929685 ; Installed on: 01c81a2724ae7b96

Hot Fix ID: KB929731 ; Installed on: 01c918a0035385dc

...

You can see that the "Installed on" format is a long hex value.

I searched in the web but found only C++ examples:

FILETIME installFileTime;

SYSTEMTIME installSysTime;

swscanf_s(InstalledOn,L"%08x%08x",

&installFileTime.dwHighDateTime, &installFileTime.dwLowDateTime);

FileTimeToSystemTime( &installFileTime, &installSysTime);

StringCchPrintf(InstalledOn,wcslen(InstalledOn),L"%d/%d/%d",

installSysTime.wMonth,installSysTime.wDay,installSysTime.wYear);

But I've no C/C++ knowledge! Can somebody translate it to AutoIt code format?

Thanks,

UEZ

:)

It's a 64 integer representing the number of 100ns ticks since 01 January, 1601. No, I didn't just make that up. :)

There are many examples already posted to convert back to date/time format. This is one:

#include <Date.au3>

           ; ... rest of the code

           ; Convert 100ns count to integer seconds
            $iSeconds = Floor($objItem.InstalledOn / 10000000)

           ; Convert seconds since 12:00AM January 01, 1601 to date string
            $sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")

           ; Display result
            MsgBox(64, "Installed On", "$sInstalledOn = " & $sInstalledOn & " Zulu (UTC)")

o:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That's not working this way because of 64-bit integer: :)

#include 
Global $system = "Localhost"
Global $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $system & "\root\cimv2")
Global $objItem

Test($system)

Func Test($srv)
    Local $colItems = $objWMIService.ExecQuery("Select HotFixID, InstalledOn from Win32_QuickFixEngineering Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'", "WQL", 0x30)
    For $objItem In $colItems
    
       ; Convert 100ns count to integer seconds
        $iSeconds = Floor($objItem.InstalledOn / 10000000)
       ; Convert seconds since 12:00AM January 01, 1601 to date string
        $sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")

        ConsoleWrite("Hot Fix ID: " & $objItem.HotFixID & " ; " & "Installed on: " & $sInstalledOn & @CRLF)
    Next
EndFunc

Output is now:

Hot Fix ID: KB929550 ; Installed on: 1601/01/01 00:00:00

Hot Fix ID: KB929685 ; Installed on: 1601/01/01 00:00:00

Hot Fix ID: KB929731 ; Installed on: 1601/01/01 00:00:00

Variable $iSeconds is always 0.

I assume that variable needs to be declared as int64. Is this possible?

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

That's not working this way because of 64-bit integer: :)

#include 
Global $system = "Localhost"
Global $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $system & "\root\cimv2")
Global $objItem

Test($system)

Func Test($srv)
    Local $colItems = $objWMIService.ExecQuery("Select HotFixID, InstalledOn from Win32_QuickFixEngineering Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'", "WQL", 0x30)
    For $objItem In $colItems
    
    ; Convert 100ns count to integer seconds
        $iSeconds = Floor($objItem.InstalledOn / 10000000)
    ; Convert seconds since 12:00AM January 01, 1601 to date string
        $sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")

        ConsoleWrite("Hot Fix ID: " & $objItem.HotFixID & "; " & "Installed on: " & $sInstalledOn & @CRLF)
    Next
EndFunc

Output is now:

Hot Fix ID: KB929550 ; Installed on: 1601/01/01 00:00:00

Hot Fix ID: KB929685 ; Installed on: 1601/01/01 00:00:00

Hot Fix ID: KB929731 ; Installed on: 1601/01/01 00:00:00

Variable $iSeconds is always 0.

I assume that variable needs to be declared as int64. Is this possible?

UEZ

My mistake. I was wrong about the property type. At least on XP Pro SP3, that property returns a normal string:
#include <Date.au3>

Global $system = "Localhost"

Test($system)

Func Test($srv)
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $srv & "\root\cimv2")
    Local $sQuery = "Select HotFixID, InstalledOn " & _
            "from Win32_QuickFixEngineering " & _
            "Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'"
    Local $colItems = $objWMIService.ExecQuery($sQuery, "WQL", 0x30)
    Local $iInstalledOnHigh, $iInstalledOnLow
    For $objItem In $colItems
        $sInstalledOn = $objItem.InstalledOn
        ConsoleWrite("Debug:  ID = " & $objItem.HotFixID & "  Installed On = " & $sInstalledOn & _
                "  Type = " & VarGetType($sInstalledOn) & @LF)
    Next
EndFunc

Part of output:

Debug:  ID = KB952287  Installed On = 11/10/2008  Type = String
Debug:  ID = KB952954  Installed On = 9/16/2008  Type = String
Debug:  ID = KB953839  Installed On = 10/1/2008  Type = String

Can you run this on Vista and post the result so we can see the type (want to know if it's an object).

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

My mistake. I was wrong about the property type. At least on XP Pro SP3, that property returns a normal string:

#include <Date.au3>
   
   Global $system = "Localhost"
   
   Test($system)
   
   Func Test($srv)
       Local $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $srv & "\root\cimv2")
       Local $sQuery = "Select HotFixID, InstalledOn " & _
               "from Win32_QuickFixEngineering " & _
               "Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'"
       Local $colItems = $objWMIService.ExecQuery($sQuery, "WQL", 0x30)
       Local $iInstalledOnHigh, $iInstalledOnLow
       For $objItem In $colItems
           $sInstalledOn = $objItem.InstalledOn
           ConsoleWrite("Debug:  ID = " & $objItem.HotFixID & "  Installed On = " & $sInstalledOn & _
                   "  Type = " & VarGetType($sInstalledOn) & @LF)
       Next
   EndFunc

Part of output:

Debug:  ID = KB952287  Installed On = 11/10/2008  Type = String
   Debug:  ID = KB952954  Installed On = 9/16/2008  Type = String
   Debug:  ID = KB953839  Installed On = 10/1/2008  Type = String

Can you run this on Vista and post the result so we can see the type (want to know if it's an object).

:)

I'm running Vista x32 without SP.

Here snippet of the output:

Debug: ID = KB929550 Installed On = 01c918a0035385dc Type = String

Debug: ID = KB929685 Installed On = 01c81a2724ae7b96 Type = String

Debug: ID = KB929731 Installed On = 01c918a0035385dc Type = String

This "problem" can only be seen on Vista and probably Server 2008 (not tested).

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I'm running Vista x32 without SP.

Here snippet of the output:

Debug: ID = KB929550 Installed On = 01c918a0035385dc Type = String

Debug: ID = KB929685 Installed On = 01c81a2724ae7b96 Type = String

Debug: ID = KB929731 Installed On = 01c918a0035385dc Type = String

This "problem" can only be seen on Vista and probably Server 2008 (not tested).

UEZ

OK, got it now. It is a 64-bit integer, but returned as a string. So we break it into two 32-bit hex numbers with simple string manipulation and convert. This demo works with just the values since where they came from doesn't matter at this point:
#include <Date.au3>

; Added fourth value to test negative Int32 check
Global $avTimes[4] = ["01c918a0035385dc", "01c81a2724ae7b96", "01c918a0035385dc", "01c918a0835385dc"]

For $n = 0 To UBound($avTimes) - 1
 ; Convert hex string to large number equivelent to 100ns count
    $iInstalledOnHigh = Dec(StringMid($avTimes[$n], 1, 8))
    $iInstalledOnLow = Dec(StringMid($avTimes[$n], 9))
 ; Compensate for IADsLargeInteger interface error where low part is a negative Int32
    If $iInstalledOnLow < 0 Then $iInstalledOnHigh += 1
    ConsoleWrite("Debug:  High = " & $iInstalledOnHigh & "  Low = " & $iInstalledOnLow & @LF)
 
 ; Sum value to large number (AutoIt float type)
    $iInstalledOn = $iInstalledOnHigh * 2 ^ 32
    $iInstalledOn += $iInstalledOnLow
        
 ; Convert 100ns count to integer seconds
    $iSeconds = Floor($iInstalledOn / 10000000)
        
 ; Convert seconds since 12:00AM January 01, 1601 to date string
    $sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
        
 ; Display results
    ConsoleWrite("Debug:  Input = " & $avTimes[$n] & "  Output (Installed On) = " & $sInstalledOn & @LF)
Next

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

OK, got it now. It is a 64-bit integer, but returned as a string. So we break it into two 32-bit hex numbers with simple string manipulation and convert. This demo works with just the values since where they came from doesn't matter at this point:

#include <Date.au3>
     
    ; Added fourth value to test negative Int32 check
     Global $avTimes[4] = ["01c918a0035385dc", "01c81a2724ae7b96", "01c918a0035385dc", "01c918a0835385dc"]
     
     For $n = 0 To UBound($avTimes) - 1
     ; Convert hex string to large number equivelent to 100ns count
          $iInstalledOnHigh = Dec(StringMid($avTimes[$n], 1, 8))
          $iInstalledOnLow = Dec(StringMid($avTimes[$n], 9))
     ; Compensate for IADsLargeInteger interface error where low part is a negative Int32
          If $iInstalledOnLow < 0 Then $iInstalledOnHigh += 1
          ConsoleWrite("Debug:  High = " & $iInstalledOnHigh & "  Low = " & $iInstalledOnLow & @LF)
      
     ; Sum value to large number (AutoIt float type)
          $iInstalledOn = $iInstalledOnHigh * 2 ^ 32
          $iInstalledOn += $iInstalledOnLow
              
     ; Convert 100ns count to integer seconds
          $iSeconds = Floor($iInstalledOn / 10000000)
              
     ; Convert seconds since 12:00AM January 01, 1601 to date string
          $sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
              
     ; Display results
          ConsoleWrite("Debug:  Input = " & $avTimes[$n] & "  Output (Installed On) = " & $sInstalledOn & @LF)
     Next

:)

I mentioned in my 2nd post that this number is a 64-bit integer and I also tried to convert it:

$part1= 0x12345678
$part2 = 0x87654321
$int64 = Hex($part1) + Hex($part2 * 2^64)
ConsoleWrite(Hex($int64) & @CRLF)
$iSeconds = Floor(Hex($int64) / 10000000)
$sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
MsgBox(0, "Test", $sInstalledOn)

But it didn't work :)

Anyway, thanks for your help. I will implement it to the example above when I'm at home again!

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Here the code:

#include <Date.au3>
Global $system = "Localhost"
Global $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $system & "\root\cimv2")
Global $objItem
Hotfix($system)

Func Hotfix($srv)
    Local  $colItems= $objWMIService.ExecQuery("SELECT Caption From Win32_OperatingSystem", "WQL", 0x30)
    Local $OS, $sHotfixID, $sInstalledOn, $Hotfix
    For $objItem In $colItems
        $OS = $objItem.Caption
    Next

    Local $sQuery = "Select HotFixID, InstalledOn " & _
            "from Win32_QuickFixEngineering " & _
            "Where HotfixID < '{' And HotfixID <> 'Q147222' And HotfixID <> 'File 1'"
    Local $colItems = $objWMIService.ExecQuery($sQuery, "WQL", 0x30)

    For $objItem In $colItems
        $sInstalledOn = $objItem.InstalledOn
        $sHotfixID = $objItem.HotFixID
        If StringInStr($OS, "Vista") > 0 Or StringInStr($OS, "2008") > 0 Then
            $high = Dec(StringMid($sInstalledOn, 1, 8))
            $low = Dec(StringMid($sInstalledOn, 9))
            $int64 = $high * 2^32 + $low ;hex calculation is not working
            $iSeconds = Floor($int64 / 10000000)
            $sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
        EndIf
        $Hotfix &= $sHotfixID & " - " & $sInstalledOn & @CRLF
    Next
    ConsoleWrite($Hotfix & @CRLF)
    MsgBox(0, "Hofix", $Hotfix)
EndFunc

@PsaltyDS: thanks for your help! :)

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...