1. 程式人生 > >Windows 登錄檔 16進位制時間轉換( Convert Reg_binary Time to a Datetime )

Windows 登錄檔 16進位制時間轉換( Convert Reg_binary Time to a Datetime )

背景:

  Windows登錄檔中,存在大量16進位制的時間,以 reg_binary儲存在登錄檔中。

  例如: 0D 6C A4 4B 37 C5 CE 01

  這種值日常報表中需要轉換為適合人閱讀的格式,例項如下:

function Convert-BinaryDateTime
{
    [CmdletBinding()]
    [Alias()]
    [OutputType([DateTime])]
    Param
    (
        # 16進位制 bytes陣列
        [Parameter(Mandatory=$true,
                   Position=0)]
        $bytes
    )

    [long]$filedate = (((((((
            [long]$bytes[7] * 256 +
            [long]$bytes[6]) * 256 + 
            [long]$bytes[5]) * 256 + 
            [long]$bytes[4]) * 256 + 
            [long]$bytes[3]) * 256 + 
            [long]$bytes[2]) * 256 + 
            [long]$bytes[1]) * 256 + 
            [long]$bytes[0])
     [DateTime]$returnDate = [datetime]::FromFileTime($filedate)
     #DateTime.FromFileTime($filedate)
     return $returnDate
}
Convert-BinaryDateTime -bytes ((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft Antimalware\Signature Updates').SignaturesLastUpdated)

2018年12月7日 10:33:12

 

參考巨硬:

https://social.technet.microsoft.com/wiki/contents/articles/20179.simple-class-to-convert-reg-binary-time-to-a-datetime-object-in-c.aspx