注册表修改( RegCreateKeyEx , RegSetValueEx )
来源:互联网 发布:平价眼影推荐 知乎 编辑:程序博客网 时间:2024/04/30 05:10
今天的一个程序需要在注册表中添加开机启动,于是想到用程序实现,Google & MSDN 了一下,其实还是很容易实现。
比如我需要在开机的时候,让系统自动运行 C:/Program Files/UDP Clt.exe。步骤如下:
1. #include <windows.h>
2. 调用 platform SDK: ::RegCreateKeyEx() 创建/打开注册表的键值, 查阅MSDN如下:
LONG RegCreateKeyEx(
HKEY hKey, // handle to an open key
LPCTSTR lpSubKey, // address of subkey name
DWORD Reserved, // reserved
LPTSTR lpClass, // address of class string
DWORD dwOptions, // special options flag
REGSAM samDesired, // desired security access
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// address of key security structure
PHKEY phkResult, // address of buffer for opened handle
LPDWORD lpdwDisposition // address of disposition value buffer
);
HKEY hKey, // handle to an open key
LPCTSTR lpSubKey, // address of subkey name
DWORD Reserved, // reserved
LPTSTR lpClass, // address of class string
DWORD dwOptions, // special options flag
REGSAM samDesired, // desired security access
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// address of key security structure
PHKEY phkResult, // address of buffer for opened handle
LPDWORD lpdwDisposition // address of disposition value buffer
);
RegCreateKeyEx() 在键值存在的情况下将打开该键值,如不存在将创建一个键值。
3. 调用 ::RegSetValueEx(),修改键值
LONG RegSetValueEx( HKEY hKey, LPCTSTR lpValueName, DWORD Reserved, DWORD dwType, const BYTE* lpData, DWORD cbData);
4. 调用 ::RegCloseKey() 关闭该键值
程序实现如下:
- #include <windows.h>
- #include <stdio.h>
- #define _T(a) a
- int main()
- {
- HKEY hKEY;
- LPCTSTR path;
- long ret;
- // specific subkey
- path = _T("SOFTWARE//Microsoft//Windows//CurrentVersion//Run");
- // create key, if already exit open it
- ret = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, path, NULL, NULL,
- REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKEY, NULL);
- if(ret != ERROR_SUCCESS)
- {
- // create / open failed
- printf("Error ! RegCreateKeyEx() failed!/n");
- exit(0);
- }
- unsigned char tmp[256] = "/0";
- DWORD size;
- // specific key value
- sprintf((char *)tmp, "C://program files//UDP Clt.exe");
- size = strlen((char *)tmp) + 1;
- // set value
- ret = ::RegSetValueEx(hKEY,"UDP Clt",NULL,REG_SZ,tmp,size);
- if(ret != ERROR_SUCCESS)
- {
- // set failed
- printf("Error ! RegSetValueEx() failed!/n");
- exit (0);
- }
- // close key
- ::RegCloseKey(hKEY);
- return 0;
- }
- 注册表修改( RegCreateKeyEx , RegSetValueEx )
- 注册表RegOpenKeyEx、RegQueryValueEx、RegCreateKeyEx和RegSetValueEx编程
- 注册表中RegSetValueEx用法
- RegCreateKey、RegSetValueEx、RegOpenKey、RegQueryValueEx操作注册表
- RegCreateKeyEx
- VC在Unicode下RegSetValueEx写入注册表乱码问题
- 注册表修改
- 修改注册表
- 修改注册表
- 修改注册表
- 注册表修改
- 修改注册表
- 修改注册表
- 注册表修改
- 修改注册表
- 修改注册表
- VC MFC 写注册表 开机自启 开机自动运行 RegSetValueEx
- RegSetValueEx写注册表如果出现键值是乱码用下面的方法
- 正则表达式笔记(学习)
- 将后台窗口激活到前台的方法
- 2007全国大学生电子设计竞赛设计报告要求
- 著名的SQL流量注入(SQL注入)攻击法
- 史玉柱10大广告法则
- 注册表修改( RegCreateKeyEx , RegSetValueEx )
- JAVA设计模式学习之----创建模式:工厂模式(抽象工厂)
- hpux (console is on a serial device,no further output will appear on this output device)
- Struts 1.3.10 上传文件时发生问题。1.3.8,1.2.9没有类似问题
- HP-EVA4400安装
- BST二叉搜索树的实现
- “逆市新宠”母婴网站有望提前盈利
- 创业公司的“四不五缺”!
- [strlen的GNU实现]有趣的代码