반응형
public class StartUpHelper
{
private string programName;
private string exeFilePath;
private const string AutoRunRegistryKeyPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
public StartUpHelper(string programName , string exeFilePath)
{
this.programName = programName;
this.exeFilePath = string.Format($"\"{exeFilePath}\"");
}
public bool IsReregistered()
{
bool isReregistered = false;
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(AutoRunRegistryKeyPath, true);
try
{
if (registryKey.GetValue(programName) == null) return false;
string value = (string)registryKey.GetValue(programName);
isReregistered = value == exeFilePath;
}
catch (Exception)
{
isReregistered = false;
}
finally
{
registryKey.Close();
}
return isReregistered;
}
public void RegisterStartUp()
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(AutoRunRegistryKeyPath, true);
registryKey.SetValue(programName, exeFilePath);
registryKey.Close();
}
public void UnRegisterStartUp()
{
if (!IsReregistered()) return;
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(AutoRunRegistryKeyPath, true);
registryKey.DeleteValue(programName, false);
registryKey.Close();
}
}
반응형
'[====== Development ======] > C#' 카테고리의 다른 글
WPF Code behind에서 Grid안의 Control 의 위치를 변경하는 방법 (0) | 2021.04.19 |
---|---|
C# Coding Standards and Naming Conventions (0) | 2021.04.19 |
String Extension Method (0) | 2021.04.19 |
All C# Extension Methods (0) | 2021.04.19 |
Using Task and Progress window (0) | 2021.04.16 |