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 AsLongValue= BitConverter.ToInt64(val, 0); return DateTime.FromFileTime(AsLongValue); }
No comments:
Post a Comment