Вывести параметр реестра для получения даты установки системы - C#

Узнай цену своей работы

Формулировка задачи:

добрый день. Подскажите, как узнать дату установления винды через параметр реестра HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion Как вывести значение переменной installdata? заранее спасибо.

Решение задачи: «Вывести параметр реестра для получения даты установки системы»

textual
Листинг программы
  1. using System;
  2. using Microsoft.Win32;
  3.  
  4. public class Example
  5. {
  6.     public static void Main()
  7.     {
  8.         // The name of the key must include a valid root.
  9.         const string userRoot = "HKEY_CURRENT_USER";
  10.         const string subkey = "RegistrySetValueExample";
  11.         const string keyName = userRoot + "\\" + subkey;
  12.  
  13.         // An int value can be stored without specifying the
  14.         // registry data type, but long values will be stored
  15.         // as strings unless you specify the type. Note that
  16.         // the int is stored in the default name/value
  17.         // pair.
  18.         Registry.SetValue(keyName, "", 5280);
  19.         Registry.SetValue(keyName, "TestLong", 12345678901234,
  20.             RegistryValueKind.QWord);
  21.  
  22.         // Strings with expandable environment variables are
  23.         // stored as ordinary strings unless you specify the
  24.         // data type.
  25.         Registry.SetValue(keyName, "TestExpand", "My path: %path%");
  26.         Registry.SetValue(keyName, "TestExpand2", "My path: %path%",
  27.             RegistryValueKind.ExpandString);
  28.  
  29.         // Arrays of strings are stored automatically as  
  30.         // MultiString. Similarly, arrays of Byte are stored
  31.         // automatically as Binary.
  32.         string[] strings = {"One", "Two", "Three"};
  33.         Registry.SetValue(keyName, "TestArray", strings);
  34.  
  35.         // Your default value is returned if the name/value pair
  36.         // does not exist.
  37.         string noSuch = (string) Registry.GetValue(keyName,
  38.             "NoSuchName",
  39.             "Return this default if NoSuchName does not exist.");
  40.         Console.WriteLine("\r\nNoSuchName: {0}", noSuch);
  41.  
  42.         // Retrieve the int and long values, specifying  
  43.         // numeric default values in case the name/value pairs
  44.         // do not exist. The int value is retrieved from the
  45.         // default (nameless) name/value pair for the key.
  46.         int tInteger = (int) Registry.GetValue(keyName, "", -1);
  47.         Console.WriteLine("(Default): {0}", tInteger);
  48.         long tLong = (long) Registry.GetValue(keyName, "TestLong",
  49.             long.MinValue);
  50.         Console.WriteLine("TestLong: {0}", tLong);
  51.  
  52.         // When retrieving a MultiString value, you can specify
  53.         // an array for the default return value.  
  54.         string[] tArray = (string[]) Registry.GetValue(keyName,
  55.             "TestArray",
  56.             new string[] {"Default if TestArray does not exist."});
  57.         for(int i=0; i<tArray.Length; i++)
  58.         {
  59.             Console.WriteLine("TestArray({0}): {1}", i, tArray[i]);
  60.         }
  61.  
  62.         // A string with embedded environment variables is not
  63.         // expanded if it was stored as an ordinary string.
  64.         string tExpand = (string) Registry.GetValue(keyName,
  65.              "TestExpand",
  66.              "Default if TestExpand does not exist.");
  67.         Console.WriteLine("TestExpand: {0}", tExpand);
  68.  
  69.         // A string stored as ExpandString is expanded.
  70.         string tExpand2 = (string) Registry.GetValue(keyName,
  71.             "TestExpand2",
  72.             "Default if TestExpand2 does not exist.");
  73.         Console.WriteLine("TestExpand2: {0}...",
  74.             tExpand2.Substring(0, 40));
  75.  
  76.         Console.WriteLine("\r\nUse the registry editor to examine the key.");
  77.         Console.WriteLine("Press the Enter key to delete the key.");
  78.         Console.ReadLine();
  79.         Registry.CurrentUser.DeleteSubKey(subkey);
  80.     }
  81. }
  82. //
  83. // This code example produces output similar to the following:
  84. //
  85. //NoSuchName: Return this default if NoSuchName does not exist.
  86. //(Default): 5280
  87. //TestLong: 12345678901234
  88. //TestArray(0): One
  89. //TestArray(1): Two
  90. //TestArray(2): Three
  91. //TestExpand: My path: %path%
  92. //TestExpand2: My path: D:\Program Files\Microsoft.NET\...
  93. //
  94. //Use the registry editor to examine the key.
  95. //Press the Enter key to delete the key.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

13   голосов , оценка 3.769 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы