Yes, it is a 8 bytes filetime structure.
I found a sample to get lastshutdowntim e, it will get the 8 bytes binary
value.
But it is VB6 and use the RegQueryValueEx function.
If i have 8 bytes binary value, how to convert it to date and time using
VB.Net?
I dont know the relation of 8 bytes and Date.
Thank you
Option Explicit
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''
' Copyright ?1996-2005 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''
Private Const MAX_COMPUTERNAM E As Long = 16
Private Const REG_BINARY As Long = &H3
Private Const HKEY_LOCAL_MACH INE = &H80000002
Private Const ERROR_SUCCESS As Long = 0
Private Const STANDARD_RIGHTS _READ As Long = &H20000
Private Const KEY_QUERY_VALUE As Long = &H1
Private Const KEY_ENUMERATE_S UB_KEYS As Long = &H8
Private Const KEY_NOTIFY As Long = &H10
Private Const SYNCHRONIZE As Long = &H100000
Private Const KEY_READ As Long = ((STANDARD_RIGH TS_READ Or _
KEY_QUERY_VALUE Or _
KEY_ENUMERATE_S UB_KEYS Or _
KEY_NOTIFY) And _
(Not SYNCHRONIZE))
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type TIME_ZONE_INFOR MATION
Bias As Long
StandardName(0 To 63) As Byte
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Function GetTimeZoneInfo rmation Lib "kernel32" _
(lpTimeZoneInfo rmation As TIME_ZONE_INFOR MATION) As Long
Private Declare Function SystemTimeToTzS pecificLocalTim e Lib "kernel32" _
(lpTimeZone As TIME_ZONE_INFOR MATION, _
lpUniversalTime As SYSTEMTIME, _
lpLocalTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToSyste mTime Lib "kernel32" _
(lpFileTime As FILETIME, _
lpSystemTime As SYSTEMTIME) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.d ll" _
Alias "RegOpenKey ExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.d ll" _
Alias "RegQueryValueE xA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
lpData As Any, _
lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.d ll" _
(ByVal hKey As Long) As Long
Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long
Private Sub Form_Load()
Command1.Captio n = "Last Shutdown Date"
Check1.Caption = "Include time"
Text1.Text = ""
End Sub
Private Sub Command1_Click( )
Dim buff As String
Dim bIncludeTime As Boolean
bIncludeTime = Check1.Value = vbChecked
buff = GetLastSystemSh utdown(bInclude Time)
Text1.Text = buff
End Sub
Private Function GetLastSystemSh utdown(bInclude Time As Boolean) As String
Dim hKey As Long
Dim sKey As String
Dim sValueName As String
Dim ft As FILETIME 'value to retrieve
Dim cbData As Long 'size of data
sKey = "System\Current ControlSet\Cont rol\Windows"
sValueName = "ShutdownTi me"
If RegOpenKeyEx(HK EY_LOCAL_MACHIN E, _
sKey, _
0&, _
KEY_READ, _
hKey) = ERROR_SUCCESS Then
If hKey <> 0 Then
'retrieve the passed value if present
cbData = Len(ft)
If RegQueryValueEx (hKey, _
sValueName, _
0&, _
REG_BINARY, _
ft, _
cbData) = ERROR_SUCCESS Then
GetLastSystemSh utdown = GetFileToSystem Date(ft, bIncludeTime)
End If 'RegQueryValueE x
'clean-up
RegCloseKey hKey
End If 'hKey
End If 'RegOpenKeyEx
End Function
Private Function GetFileToSystem Date(ft As FILETIME, _
Optional bIncludeTime As Boolean =
False) As String
Dim buff As String
Dim st As SYSTEMTIME 'system (UNC) time
Dim lt As SYSTEMTIME 'local time
Dim tz As TIME_ZONE_INFOR MATION
If FileTimeToSyste mTime(ft, st) Then
'retrieve the local time zone info
GetTimeZoneInfo rmation tz
'convert the system time returned above
'to a local time taking the time zone
'info into account
SystemTimeToTzS pecificLocalTim e tz, st, lt
'now just write it out
buff = Format$(DateSer ial(lt.wYear, lt.wMonth, lt.wDay), "Long Date")
If bIncludeTime Then
buff = buff & " @ " & Format$(TimeSer ial(lt.wHour, _
lt.wMinute, _
lt.wSecond), _
"Long Time")
End If
GetFileToSystem Date = buff
Else
GetFileToSystem Date = ""
End If
End Function
"Mattias Sjögren" <ma************ ********@mvps.o rg> дÈëÏûÏ¢ÐÂÎÅ:uO **************@ tk2msftngp13.ph x.gbl...
The 16 byte Binary value will store the last access date and time, can
anyone know how to recover the bianry value to date?
Looks like you should interpret the last 8 bytes as a FILETIME
structure.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.