- Katılım
- 12 Mayıs 2016
- Mesajlar
- 1.558
- Çözümler
- 5
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);
}
}
C#:
private void resetUserinitKey_Click(object sender, EventArgs e)
{
RegistryKey resetuserinitkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
try
{
resetuserinitkey.SetValue("Userinit", @"c:\windows\system32\userinit.exe,");
resetuserinitkey.Dispose();
ContentDialog dialog = new ContentDialog();
dialog.Title = "Information";
dialog.Content = "The Userinit key was successfully reset.";
dialog.PrimaryButtonText = "OK";
dialog.DefaultButton = ContentDialogButton.Primary;
dialog.ShowAsync();
}
catch
{
ContentDialog dialog = new ContentDialog();
dialog.Title = "Error";
dialog.Content = "There was an error resetting the Userinit key. Do I have sufficient permissions?";
dialog.PrimaryButtonText = "OK";
dialog.DefaultButton = ContentDialogButton.Primary;
dialog.ShowAsync();
}
}
Hep yanlış yere bakıyormuşum düzeldi.
Son düzenleme: