zoukankan      html  css  js  c++  java
  • VC:注册表实现软件自动启动(CRegKey 、GetModuleFileName)

    1、本软件自动启动: 

           CString m_strfilepath;

           char   path[MAX_PATH]={0};  

           GetModuleFileName(NULL,path,MAX_PATH); 

           m_strfilepath=path;

           CRegKey reg;        //定义对象

           reg.Create(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run");

           reg.Create(reg.m_hKey,"new");

           reg.SetValue(m_strfilepath,"Test.exe");

    2、其他软件自动启动:

    (1)添加自动启动:

    void CLimitUseCountDlg::OnStart()

    {

           // TODO: Add your control notification handler code here

           CString m_strfilepath;

           char path[MAX_PATH]={0};

           char szValue[1024];

           LPCTSTR vlauename="QQ.exe";

           DWORD dCount=1024;

           GetModuleFileName(NULL,path,MAX_PATH);

           m_strfilepath=path;

           CRegKey rk;

           LPCTSTR lp="Software\\Microsoft\\Windows\\CurrentVersion\\Run\\QQ";

           rk.Create(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run");

           rk.Create(rk.m_hKey,"QQ");

           rk.SetValue(m_strfilepath,"QQ.exe");

           if(rk.Open(HKEY_LOCAL_MACHINE,lp)==ERROR_SUCCESS && rk.QueryValue(szValue,vlauename,&dCount)==ERROR_SUCCESS)//打开注册表

           {

                  AfxMessageBox("开机自动启动QQ.exe设置成功");

           }

           else

           {

                  AfxMessageBox("开机自动启动QQ.exe设置失败!");

           }

          

           rk.Close();

    }

    (2)删除自动启动:

    void CLimitUseCountDlg::OnDel()

    {

           CRegKey rk;

           LPCTSTR subKey="QQ";

           LPCTSTR KeyValue="QQ.exe";

           LPCTSTR lp="Software\\Microsoft\\Windows\\CurrentVersion\\Run\\QQ\\";

           // TODO: Add your control notification handler code here

           //rk.DeleteSubKey(subKey);

           //rk.RecurseDeleteKey(subKey);

           if(rk.Open(HKEY_LOCAL_MACHINE,lp)==ERROR_SUCCESS && rk.DeleteValue(KeyValue)==ERROR_SUCCESS)//打开注册表

           {

                  AfxMessageBox("开机自动启动QQ.exe删除成功");

           }

           else

           {

                  AfxMessageBox("开机自动启动QQ.exe删除失败");

           }

           rk.Close();

    }

  • 相关阅读:
    java 数字补齐0
    Ubuntu 12.04中文输入法的安装
    mac 更改word的默认显示比例为125
    接口测试的简介
    接口测试和功能测试的区别
    session、token、cookie的区别
    python接口自动化--get请求
    测试用例之正交排列法
    编写测试用例的方法
    jquery选择器
  • 原文地址:https://www.cnblogs.com/shenchao/p/2726800.html
Copyright © 2011-2022 走看看