Как узнать дату установки Windows

Все об администрировании рабочих станций Windows 95/98/NT/2000/XP/7/8. То, чего не найдешь в бескрайних просторах Интернета. Решения тех проблем, которые не решаются типовыми ответами, которые можно получить в техподдержке Майкрософта - а именно: переустановить продукт или купить какой-ть другой лицензионный диск.


Модератор: UncleFather

Аватара пользователя
UncleFather
Site Admin
Сообщения: 1505
Зарегистрирован: 17 авг 2004 16:20, Вт
Контактная информация:

Как узнать дату установки Windows

Сообщение UncleFather »

Задача:

Необходимо узнать дату установки операционной системы Microsoft Windows XP/VIsta/7/8. То есть необходим универсальный метод поиска даты установки.

Решение:

Вариант 1

Первым делом, естественно, обращаемся к реестру Windows: в ветке: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion есть параметр типа REG_DWORD с именем InstallDate.

Время установки ОС в реестре:
01.JPG

Значение этого параметра и есть искомое дата и время в Unix Timestamp - формате.

Конвертировать его в читаемый формат, можно, разными способами:

  • С помощью online конвертера, например на страничке Date - Unix Time Converter with bulk and custom date format capability:

    Онлайн timestamp конвертер
    02.JPG
  • С помощью Microsoft Excel. О том как это сделать читаем здесь и здесь.

    Конвертация Unix Timestamp в MS Office Excel:
    05.JPG

    В Microsoft Office Excel можно вообще сразу получить дату и время установки Windows в удобном формате. Для этого нужно:

    1. вставить следующий код Visual Basic в код листа, на котором хотим получить дату:

      VBA код листа:

      Код: Выделить всё

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim MyRange As Range
          If Target.Address = "$A$2" Then
              Set WshShell = CreateObject("WScript.Shell")
              InstallDate = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate")
              Set MyRange = Range("A1:B1")
              With MyRange
                  .HorizontalAlignment = xlCenter
                  .VerticalAlignment = xlCenter
                  .WrapText = True
                  .Orientation = 0
                  .AddIndent = False
                  .IndentLevel = 0
                  .ShrinkToFit = False
                  .ReadingOrder = xlContext
                  .MergeCells = True
                  .FormulaLocal = "Время установки Windows"
                  .Font.Bold = True
              End With
              Rows("1:1").RowHeight = 24.75
              Set MyRange = Range("A1:B4")
              With MyRange.Borders(xlEdgeLeft)
                  .LineStyle = xlDouble
                  .Weight = xlThick
                  .ColorIndex = xlAutomatic
              End With
              With MyRange.Borders(xlEdgeTop)
                  .LineStyle = xlDouble
                  .Weight = xlThick
                  .ColorIndex = xlAutomatic
              End With
              With MyRange.Borders(xlEdgeBottom)
                  .LineStyle = xlDouble
                  .Weight = xlThick
                  .ColorIndex = xlAutomatic
              End With
              With MyRange.Borders(xlEdgeRight)
                  .LineStyle = xlDouble
                  .Weight = xlThick
                  .ColorIndex = xlAutomatic
              End With
              With MyRange.Borders(xlInsideVertical)
                  .LineStyle = xlContinuous
                  .Weight = xlThin
                  .ColorIndex = xlAutomatic
              End With
              With MyRange.Borders(xlInsideHorizontal)
                  .LineStyle = xlContinuous
                  .Weight = xlThin
                  .ColorIndex = xlAutomatic
              End With
              
              Range("A2:A2").Formula = "Реестр"
              Range("A3:A3").Formula = "UTC"
              Range("A4:A4").Formula = "Local"
              Range("B2:B2").Formula = InstallDate
              Range("B3:B3").FormulaLocal = "=B2/86400+Дата(1970;1;1)"
              Range("B4:B4").FormulaLocal = "=B2/86400+LocalOffsetFromGMT()/1440+Дата(1970;1;1)"
              Range("B2:B2").NumberFormat = "General"
              Range("B3:B4").NumberFormat = "dd/mm/yy h:mm;@"
              Columns("A:B").EntireColumn.AutoFit
          End If
      End Sub
      
      Это будет выглядеть так:
      01.jpg
    2. вставить следующий код Visual Basic в код модуля книги MS Excel:

      VBA код модуля:

      Код: Выделить всё

      Option Explicit
      Option Compare Text
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' modTimeZones
      ' By Chip Pearson, chip@cpearson.com, www.cpearson.com
      ' Date: 2-April-2008
      ' Page Specific URL: www.cpearson.com/Excel/TimeZoneAndDaylightTime.aspx
      '
      ' This module contains functions related to time zones and GMT times.
      '   Terms:
      '   -------------------------
      '   GMT = Greenwich Mean Time. Many applications use the term
      '       UTC (Universal Coordinated Time). GMT and UTC are
      '       interchangable in meaning,
      '   Local Time = The local "wall clock" time of day, that time that
      '       you would set a clock to.
      '   DST = Daylight Savings Time
      
      '   Functions In This Module:
      '   -------------------------
      '       LocalOffsetFromGMT
      '           Returns the number of minutes or hours that are to be added to
      '           the local time to get GMT. Optionally adjusts for DST.
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      
      
      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 TIME_ZONE_INFORMATION
          Bias As Long
          StandardName(0 To 31) As Integer
          StandardDate As SYSTEMTIME
          StandardBias As Long
          DaylightName(0 To 31) As Integer
          DaylightDate As SYSTEMTIME
          DaylightBias As Long
      End Type
      
      Public Enum TIME_ZONE
          TIME_ZONE_ID_INVALID = 0
          TIME_ZONE_STANDARD = 1
          TIME_ZONE_DAYLIGHT = 2
      End Enum
          
      '''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Required Windows API Declares
      '''''''''''''''''''''''''''''''''''''''''''''''''''''
      #If Win64 Then
          #If VBA7 Then    ' Windows x64, Office 2010
              Private Declare PtrSafe Function GetTimeZoneInformation Lib "kernel32" _
                  (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
              
              Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" _
                  (lpSystemTime As SYSTEMTIME)
          #Else    ' Windows x64,Office 2003-2007
              Private Declare Function GetTimeZoneInformation Lib "kernel32" _
                  (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
              
              Private Declare Sub GetSystemTime Lib "kernel32" _
                  (lpSystemTime As SYSTEMTIME)
          #End If
      #Else
          #If VBA7 Then    ' Windows x86, Office 2010
              Private Declare PtrSafe Function GetTimeZoneInformation Lib "kernel32" _
                  (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
              
              Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" _
                  (lpSystemTime As SYSTEMTIME)
          #Else    ' Windows x86, Office 2003-2007
              Private Declare Function GetTimeZoneInformation Lib "kernel32" _
                  (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
              
              Private Declare Sub GetSystemTime Lib "kernel32" _
                  (lpSystemTime As SYSTEMTIME)
          #End If
      #End If
      
      
      Public Function LocalOffsetFromGMT(Optional AsHours As Boolean = False, _
          Optional AdjustForDST As Boolean = False) As Long
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' LocalOffsetFromGMT
      ' This returns the amount of time in minutes (if AsHours is omitted or
      ' false) or hours (if AsHours is True) that should be added to the
      ' local time to get GMT. If AdjustForDST is missing or false,
      ' the unmodified difference is returned. (e.g., Kansas City to London
      ' is 6 hours normally, 5 hours during DST. If AdjustForDST is False,
      ' the resultif 6 hours. If AdjustForDST is True, the result is 5 hours
      ' if DST is in effect.)
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      
      Dim TBias As Long
      Dim TZI As TIME_ZONE_INFORMATION
      Dim DST As TIME_ZONE
      DST = GetTimeZoneInformation(TZI)
      
      If DST = TIME_ZONE_DAYLIGHT Then
          If AdjustForDST = True Then
              TBias = -(TZI.Bias + TZI.DaylightBias)
          Else
              TBias = -TZI.Bias
          End If
      Else
          TBias = -TZI.Bias
      End If
      If AsHours = True Then
          TBias = TBias / 60
      End If
      
      LocalOffsetFromGMT = TBias
      
      End Function
      
      
      Это будет выглядеть так:
      02.jpg
    3. Вернуться в оболочку MS Excel и кликнуть ячейку «A2»

    Получим красивую табличку с датой и временем установки Windows:
    03.jpg
    03.jpg (38.27 КБ) 4261 просмотр

    Готовый файл Excel качаем отсюда:

    WindowsTime.rar
    (17.96 КБ) 377 скачиваний
  • При помощи PowerShell (сразу с учетом своего часового пояса):

    Код: Выделить всё

    [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($(get-itemproperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').InstallDate))
    PowerShell time:
    07.JPG

Вариант 2

Воспользуемся командой systeminfo:

Код: Выделить всё

systeminfo |MORE

получим дату установки Windows:

SystemInfo:
08.JPG

А чтобы не выводить лишнюю информацию, можно воспользоваться командой find:

Код: Выделить всё

systeminfo | find /i "Дата установки"
SystemInfo & find:
09.JPG

Вариант 3

Теперь будем использовать WMIC:

Код: Выделить всё

wmic os get installdate

Получим дату и время в «некрасивом формате»:

WMIC:
12.JPG
12.JPG (11.59 КБ) 4263 просмотра

Вроде бы понять дату/время можно и несложно, но некрасиво. Поэтому, применим PowerShell:

Код: Выделить всё

([WMI]'').ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).InstallDate)

Вот теперь получается красиво:

WWIC & PowerShell
11.JPG

Alexander A. Manaeff©

Понравилась статья? Будем крайне признательны за репосты в соцсетях! Материально поддержать проект можно здесь

Мои странички:
ВКонтакте
Одноклассники
Youtube
Facebook
Instagram

Изображение
Изображение
Изображение
Изображение