Onaylı Üye
C#:
private void RemoveUserInitValue()
{
string keyPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";
string valueName = "Userinit";
string valueData = "%SystemRoot%\\System32\\Userinit.exe";
try
{
using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(keyPath, true))
{
if (key != null)
{
// Check if the value already exists
object? currentValue = key.GetValue(valueName);
if (currentValue == null || currentValue.ToString() != valueData)
{
// Create or update the value if it doesn't exist or has different data
key.SetValue(valueName, valueData, RegistryValueKind.String);
Console.WriteLine("Userinit value successfully added to the registry.");
}
else
{
Console.WriteLine("Userinit value already exists in the registry.");
}
}
else
{
Console.WriteLine("Error: Unable to access the registry key.");
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}