当前位置: 移动技术网 > IT编程>开发语言>c# > C#设置开机启动项、取消开机启动项

C#设置开机启动项、取消开机启动项

2019年07月18日  | 移动技术网IT编程  | 我要评论

如果想你写的程序随系统开机一起启动的话,那么你可以照下面这个方法来做。 

runwhenstart(false, application.productname, application.startuppath + @\"\\mus.exe\"); 



    /// <summary> 
    /// 开机启动项 
    /// </summary> 
    /// <param name=\"started\">是否启动</param> 
    /// <param name=\"name\">启动值的名称</param> 
    /// <param name=\"path\">启动程序的路径</param> 
    public static void runwhenstart(bool started, string name, string path) 
    { 
      registrykey hklm = registry.localmachine; 
      registrykey run = hklm.createsubkey(@\"software\\microsoft\\windows\\currentversion\\run\"); 
      if (started == true) 
      { 
        try 
        { 
          run.setvalue(name, path); 
          hklm.close(); 
        } 
        catch (exception err) 
        { 
          messagebox.show(err.message.tostring(), \"mus\", messageboxbuttons.ok, messageboxicon.error); 
        } 
      } [page]
      else 
      { 
        try 
        { 
          run.deletevalue(name); 
          hklm.close(); 
        } 
        catch (exception) 
        { 
          // 
        } 
      } 
    } 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网