MFC通过注册表 实现程序开机自动运行
来源:互联网 发布:手机通话记录软件大全 编辑:程序博客网 时间:2024/06/06 03:38
1.创建一个成员函数:
void CAutoRunByRegistryDlg::SetAutoRun(bool bAutoRun)
{
HKEY hKey;
CString strRegPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";//find the system's startup
if (bAutoRun)
{
if (RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) //open running item
{
TCHAR szModule[_MAX_PATH];
GetModuleFileName(NULL, szModule, _MAX_PATH);//Get oneself program's name
RegSetValueEx(hKey,"AutoRunByRegistry", 0, REG_SZ, (const BYTE*)(LPCSTR)szModule, strlen(szModule));
//add a child Key,and set a value="AutoRunByRegistry",it is a program name (remove .exe),of course KeyVaule can set anyone.
RegCloseKey(hKey); //close Registry
}
else
{
AfxMessageBox("the system parameters error,AutoRun fail!");
}
}
else
{
if (RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
RegDeleteValue (hKey,"AutoRunByRegistry"); //Del KeyVaule="AutoRunByRegistry", so program AutoRunByRegistry.exe will can AutoRun.
RegCloseKey(hKey);
}
}
}
2.增加函数响应:
以下代码,可以放到初始化函数OnInitDialog(),或则按钮响应函数都可以。
SetAutoRun(true); //add registrykey value
//SetAutoRun(false); //remove registrykey value
3.效果可以查看注册表:在运行中输入:regedt32.exe
然后找到路径为:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run,就可以看到注册的程序。
以上程序实现了开机启动运行自身的程序,如果想开机启动其他的应用程序,只需要在RegSetValueEx函数中把程序的完整路径名字设置OK,就可以了。
- MFC通过注册表 实现程序开机自动运行
- MFC实现程序开机自动运行
- C# WinFORM通过注册表实现开机运行
- 通过修改注册表让wince开机自动运行程序,不需要修改内核
- 开机自动运行程序的注册表设置及写法
- 注册表编程VC 使程序开机自动运行
- C# winform利用注册表信息实现开机自动运行软件
- VC MFC 写注册表 开机自启 开机自动运行 RegSetValueEx
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- Android实现开机自动运行程序
- jQuery - 设置内容和属性
- [卢卡斯定理+中国剩余定理] hdu 5446 Unknown Treasure
- js打印对象 很有用的一个函数
- MySQL集群:主从数据库配置 实现查询负载
- 为什么很多年轻人总会感到迷茫
- MFC通过注册表 实现程序开机自动运行
- android 开发第六弹--View事件传递和碎片
- 使用Eclipse构建Maven的SpringMVC项目
- Java/Android 多少年月日时分秒前
- ubuntu 13.04安装supervisor
- PopMetal和PX2上运行upstream linux kernel代码
- Web.xml配置详解之listener
- 关于创建String对象过程的内存分配
- Ubuntu adb devices :???????????? no permissions 解决方法