Основная задача программы - сменить MachineGuid. При выполнении программы выбивает такая ошибка - Exception: В экземпляре объекта не задана ссылка на объект.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Diagnostics;
class MachineGuidChanger
{
static void Main()
{
string key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography";
string r = (string)Registry.GetValue(key, "MachineGuid", (object)"default");
Console.WriteLine("Current MachineGuid: " + r);
try
{
StreamWriter sw = new StreamWriter("Backup.txt");
sw.WriteLine("Old MachineGuid: " + r);
sw.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
Guid g = Guid.NewGuid();
try
{
RegistryKey savKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography");
savKey.SetValue("MachineGuid", g);
savKey.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
string newkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography";
string newr = (string)Registry.GetValue(newkey, "MachineGuid", (object)"default");
Console.WriteLine("New MachineGuid: " + newr);
}
}
Exception, аNullReferenceException-Console.WriteLine($"{e.GetType().Name}: {e.Message}");– aepot Oct 09 '22 at 02:22RegistryKey savKey = Registry.LocalMachine.OpenSubKey(key, true);– aepot Oct 09 '22 at 02:28