例如现在我用administrator登陆时启动图中exe程序,现在切换到guest账号,上图中的exe在进程中存在,但是托盘图标看不到了
private static void RegisterAutoStart()
{
string path = Application.ExecutablePath;
string shortFileName = "NUCBox";
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run", true);
if (rgkRun == null)
{
rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run");
}
string rgkValue = rgkRun.GetValue("NUCBox") as string;
if (string.IsNullOrEmpty(rgkValue))
{
rgkRun.SetValue(shortFileName, $""{path}"");
}
rgkRun.Close();
}
private static void UnregisterAutoStart()
{
string path = Application.ExecutablePath;
string shortFileName = "NUCBox";
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
{
rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run");
}
rgkRun.DeleteValue(shortFileName, false);
rgkRun.Close();
}
将可执行文件注册为开机启动项,
– 逆光迷矢 6年前