win32 注册表操作
2024-09-26 04:53:17
创建键 RegCreateKeyEx
int SetRecordVideoSavedDays(int newSavedDays)
{
HKEY hSubKey = NULL;
LONG lRet = ;
DWORD dwType = ;
int iRet = ; do
{
if (newSavedDays < )
{
printf("error: input negative number\n");
break;
}
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Cloudsoar 3C\\ServerInfo",
, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &hSubKey, NULL);
if (ERROR_SUCCESS != lRet)
{
printf("Create Reg failed\n");
break;
} lRet = RegSetValueEx(hSubKey, "VideoSavedDays", , REG_DWORD, (BYTE*)&newSavedDays, sizeof(newSavedDays));
if (ERROR_SUCCESS != lRet)
{
printf("Set reg value VideoSavedDays failed\n");
break;
} iRet = (int)newSavedDays;
} while (); if(NULL != hSubKey)
{
RegCloseKey(hSubKey);
hSubKey = NULL;
} return iRet;
} // parameter1: out, save video saved path
// parameter2: in, save path length
BOOL GetRecordVideoSavedPath(char *pchPath,int pathBufLen)
{
HKEY hSubKey = NULL;
LONG lRet = ;
DWORD dwType = ;
DWORD dwPathLen = pathBufLen;
BOOL bRet = FALSE; do
{
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Cloudsoar 3C\\ServerInfo",
, KEY_READ, &hSubKey);
if (ERROR_SUCCESS != lRet)
{
printf("Open reg value VideoSavedPath failed\n");
break;
} lRet = RegQueryValueEx(hSubKey, "VideoSavedPath",
, &dwType, (LPBYTE)pchPath, &dwPathLen);
if (ERROR_SUCCESS != lRet)
{
printf("Query reg value VideoSavedPath failed\n");
break;
} bRet = TRUE; } while (); RegCloseKey(hSubKey); return bRet;
} BOOL SetRecordVideoSavePath(char *pchNewPath)
{
HKEY hSubKey = NULL;
LONG lRet = ;
DWORD dwType = ;
DWORD dwState = ;
BOOL bRet = FALSE; do
{
if (NULL == pchNewPath)
{
printf("error: input negative new path\n");
break;
}
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Cloudsoar 3C\\ServerInfo",
, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &hSubKey, &dwState);
if (ERROR_SUCCESS != lRet)
{
printf("Create Reg VideoSavedPath failed\n");
break;
} lRet = RegSetValueEx(hSubKey, "VideoSavedPath", , REG_SZ, (PBYTE)pchNewPath, sizeof(pchNewPath));
if (ERROR_SUCCESS != lRet)
{
printf("Set reg value VideoSavedPath failed\n");
break;
} bRet = TRUE;
} while (); RegCloseKey(hSubKey); return bRet;
}
函数原型
LONG RegCreateKeyEx(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey, // subkey name
DWORD Reserved, // reserved
LPTSTR lpClass, // class string
DWORD dwOptions, // special options
REGSAM samDesired, // desired security access
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // inheritance
PHKEY phkResult, // key handle
LPDWORD lpdwDisposition // disposition value buffer
);
参数说明
hKey: 要打开键的句柄或以下预定义句柄
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
lpSubKey: 指向一个用于定义子键路径的字符串
Reserved,dwOptions,samDesired: 置0
lpClass,lpSecurityAttributes: 置NULL
phkResult: 用于接收键句柄
lpdwDisposition: 接收的相关信息,取值如下
REG_CREATED_NEW_KEY 创建成功
REG_OPENED_EXISTING_KEY 键已存在
打开键 RegOpenKeyEx
函数原型
LONG RegOpenKeyEx(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey, // subkey name
DWORD ulOptions, // reserved
REGSAM samDesired, // security access mask
PHKEY phkResult // handle to open key
);
参数说明
hKey: 要打开键的句柄或以下预定义句柄
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
lpSubKey: 指向一个用于定义子键路径的字符串
ulOptions: 保留位,置0
samDesired: 打开键后键的操作权限
phResult: 接收打开的键的句柄
修改/添加键值 RegSetValueEx
函数原型
LONG RegSetValueEx(
HKEY hKey, // handle to key
LPCTSTR lpValueName, // value name
DWORD Reserved, // reserved
DWORD dwType, // value type
CONST BYTE *lpData, // value data
DWORD cbData // size of value data
);
参数说明
hKey: 打开键的句柄或以下预定义句柄
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
lpValueName: 键值的名称
Reserved: 保留位,置0
dwType: 键值的类型
lpData: 键值
cbData: 键值数据长度
最新文章
- JSON方式提交文档时SOLR报:AtomicUpdateDocumentMerger Unknown operation for the an atomic update, operation ignored
- MVC使用x.PagedList分页
- input输入内容时放大问题
- CSS折行小记
- css 网站变灰色
- Centos7 创建个文件 thread 怪现象
- 通过python切换hosts文件
- 2014年3月份第2周51Aspx源码发布详情
- linux上nagios安装完整版
- magento1.x 运行在 php7 优惠券的问题
- WiFi天线分集
- Android Studio 受不了了
- Storm入门(十四)Trident API Overview
- 基于OpenCv和swing的图片/视频展示Java实现
- Spring中JdbcTemplate使用RowMapper
- Unity 3D编辑器扩展介绍、教程(二) —— 创建窗口
- 利用IPC通道进行进程间通信(C#)
- Google Analytics10条有用教程(转)
- 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7
- Attribute基本介绍