重启服务器后,托盘自启动

解决服务器重启后托盘程序不自动运行的问题:

在托盘程序运行时调用以下方法即可。

/// <summary>
/// 根据注册名称和路径判断是否已注册
/// </summary>
/// <param name="regName">注册名称</param>
/// <param name="startUpPath">注册路径</param>
private void IsExistsStartRun(string regName, string startUpPath)
{
//RegistryKey loca = Registry.LocalMachine;
RegistryKey loca = Registry.CurrentUser;
RegistryKey run = loca.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");

object obj = run.GetValue(regName);
//如果未注册,进行注册操作
if (obj == null)
{
run.SetValue(regName, startUpPath);//加入注册,参数一为注册节点名称(随意)
}
}

原文地址:https://www.cnblogs.com/Violety/p/11989402.html