DateTime
can be achieved from a byte
array
with fewer statements using the BitConverter
.The following code will give the correctDateTime
from the registrypublic static DateTime GetLastShutdownDate()
{ string rKey = @"System\CurrentControlSet\Control\Windows"; Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(rKey); string rValueName = "ShutdownTime"; byte[] val = (byte[]) key.GetValue(rValueName); long AsLong
Value
= BitConverter.ToInt64(val, 0); return DateTime.FromFileTime(
AsLong
Value
); }
No comments:
Post a Comment