VC++ 读写注冊表,注冊文件图标关联
#include <string>
#include <iostream>
#include <Windows.h>
#include <shlobj.h>
using namespace std; //-------------------------------------------------------------------------
// 注冊文件图标关联
//-------------------------------------------------------------------------
// @strExt [in]: 须要检測的文件后缀(.txt)
// @strAppKey [in]: 扩展名在注冊表中的键值(txtfile)
// @strAppName [in]: 须要关联的引用程序(c:\app\app.exe)
// @strDefaultIcon [in]: 关联的图标
// @strDescribe [in]: 描写叙述
//-------------------------------------------------------------------------
void RegisterFileRelation(char *strExt,char *strAppKey,char *strAppName, char *strDefaultIcon, char *strDescribe)
{
char strTemp[_MAX_PATH];
HKEY hKey; RegCreateKey(HKEY_CLASSES_ROOT,strExt,&hKey);
RegSetValue(hKey,"",REG_SZ,strAppKey,strlen(strAppKey)+1);
RegCloseKey(hKey); RegCreateKey(HKEY_CLASSES_ROOT,strAppKey,&hKey);
RegSetValue(hKey,"",REG_SZ,strDescribe,strlen(strDescribe)+1);
RegCloseKey(hKey); sprintf(strTemp,"%s\\DefaultIcon",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
RegSetValue(hKey,"",REG_SZ,strDefaultIcon,strlen(strDefaultIcon)+1);
RegCloseKey(hKey); sprintf(strTemp,"%s\\Shell",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
RegSetValue(hKey,"",REG_SZ,"Open",strlen("Open")+1);
RegCloseKey(hKey); sprintf(strTemp,"%s\\Shell\\Open\\Command",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
sprintf(strTemp,"%s \"%%1\"",strAppName);
RegSetValue(hKey,"",REG_SZ,strTemp,strlen(strTemp)+1);
RegCloseKey(hKey);
SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST,NULL,NULL);
} //-------------------------------------------------------------------------
// 写注冊表的的方法
//-------------------------------------------------------------------------
// @root [in]: 注冊表根
// @subDir [in]: 子结构
// @regKey [in]: 注冊表项键
// @regValue [in]: 要写入的注冊表值
//-------------------------------------------------------------------------
// @return : 0表示成功,其它表示错误码
//-------------------------------------------------------------------------
int WriteRegKey(HKEY root,char * subDir,char * regKey,char * regValue){
char strTemp[_MAX_PATH];
HKEY hKey;
sprintf(strTemp,subDir); char* sclass = "";
DWORD nbf = 0;
long ret = RegCreateKeyEx(root,strTemp,0,"",REG_OPTION_NON_VOLATILE,KEY_READ|KEY_WRITE,NULL,&hKey,&nbf);
if(ret != ERROR_SUCCESS) {
return -1;
} ret = RegSetValueEx(hKey,regKey,0,REG_SZ,LPBYTE(regValue),strlen(regValue)+1);
if(ret != ERROR_SUCCESS) {
return -1;
} return 0;
} //-------------------------------------------------------------------------
// 写注冊表的的方法
//-------------------------------------------------------------------------
// @root [in] : 注冊表根
// @subDir [in] : 子结构
// @regKey [in] : 注冊表项键
// @regValue [out]: 读的的注冊表值
//-------------------------------------------------------------------------
// @return : 0表示成功,其它表示错误码
//-------------------------------------------------------------------------
int ReadRegKey(HKEY root,char * subDir,char * regKey,char* & regValue){
char strTemp[_MAX_PATH];
HKEY hKey;
sprintf(strTemp,subDir); long ret = (::RegOpenKeyExA(root,strTemp,0,KEY_READ,&hKey));
if (ret !=ERROR_SUCCESS)
{
return -1;
} DWORD valueType = REG_SZ;
DWORD cbData = 255; ret = ::RegQueryValueExA(hKey,regKey,NULL,&valueType,(LPBYTE)regValue,&cbData);
if (ret != ERROR_SUCCESS)
{
return -1;
}
RegCloseKey(hKey); return 0;
} int main(){
WriteRegKey(HKEY_CURRENT_USER,"Software\\Demo 1.0\\AppKey","path","C:\\hello\\world"); char* ret;
ret = new char[255];
ret[0] = '\0'; ReadRegKey(HKEY_CURRENT_USER,"Software\\Demo 1.0\\AppKey","path",ret);
cout << ret << endl;
delete[] ret; return 0;
}
VC++ 读写注冊表,注冊文件图标关联的更多相关文章
- QSettings配置读写-win注册表操作-ini文件读写
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QSettings配置读写-win注册表操作-ini文件读写 本文地址:http:// ...
- Delphi 7使用自定义图标关联文件类型
Delphi 7使用自定义图标关联文件类型 5.2 Delphi编程(40) 版权声明:本文为博主原创文章,未经博主允许不得转载. 在开发过程中,我们经常需要属于自己的文件类型,自定义的后缀名不仅可 ...
- QSettings读写注冊表、配置文件
简述 普通情况下.我们在开发软件过程中,都会缓存一些信息到本地,能够使用轻量级数据库sqlite.也能够操作注冊表.读写配置文件. 关于QSettings的使用前面已经介绍过了.比較具体,见" ...
- C#注冊表操作汇总
一.注冊表基本知识 1) 结构 键->项->子项->值项(名称.类型.数据) REG_SZ 字符串 REG_BINARY 二进制 REG_DWORD ...
- c++ 操作注冊表
1. 注冊表简单介绍 注冊表是为Windows NT和Windows95中全部32位硬件/驱动和32位应用程序设计的数据文件,用于存储系统和应用程序的设置信息.16位驱动在Winnt (W ...
- YII用户注冊表单的实现熟悉前台各个表单元素操作方式
模还是必须定义两个基本方法.还有部分label标签映射为汉字,假设进行表单验证,还要定义一些验证规则: <? php /* * 用户模型 * */ class user extends CAct ...
- C# 系统应用之注冊表使用具体解释
在平时做项目时,我们有时会遇到注冊表的操作,比如前面我们须要获取IE浏览器地址栏的信息.获取"我的电脑"地址栏输入的目录信息.USB近期使用信息等.注冊表项是注冊表的基本组织单位, ...
- PLSQL Developer过期要注冊表
打开执行输入 regedit 打表注冊表 删除 HKEY_CURRENT_USER\Software\Allround Automations HKEY_CURRENT_USER\Software\M ...
- 64位Windows操作系统中的注冊表
x64系统上有x64.x86两种注冊表,记录下. 64 位Windows系统中的注冊表分为 32 位注冊表项和 64 位注冊表项.很多 32 位注冊表项与其对应的 64 位注冊表项同名. 在64位版本 ...
随机推荐
- nginx,wsgi,django的关系
http://blog.csdn.net/lihao21/article/details/52304119 wsgi用于连续 nginx和django,客户端发来的请求,先经过wsgi,然后再传给dj ...
- Unicode类别
Unicode 通用类别: http://msdn.microsoft.com/zh-cn/library/20bw873z(VS.80).aspx 类别 说明 Lu 字母,大写 Ll 字母,小写 L ...
- leetcode题解:Construct Binary Tree from Preorder and Inorder Traversal (根据前序和中序遍历构造二叉树)
题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume t ...
- 在scala中:: , +:, :+, :::, +++的区别总结
初学Scala的人都会被Seq的各种操作符所confuse.下面简单列举一下各个Seq操作符的区别. 4种操作符的区别和联系 :: 该方法被称为cons,意为构造,向队列的头部追加数据,创造新的列表. ...
- ionic准备之angular基础——格式化数据以及过滤器(8)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- LeetCode-Minimum Window Substring -- 窗口问题
题目描述 Given a string S and a string T, find the minimum window in S which will contain all the charac ...
- 【Excle数据透视表】如何在组的顶部显示分类汇总
调整前 调整后 例 ...
- (五)Thymeleaf标准表达式之——[7->8]条件表达式& 默认表达式
2.7 条件表达式 模板名称:condition-express.html <1>a ? b:c (if then:else) <2>a?c (if else) 条件表达式( ...
- 如何为Apache JMeter开发插件(一)
本文转载于http://blog.csdn.net/column/details/12925.html,作者:xreztento 作者写的很精华,我打算在此系列操作一遍后,加多点截图,便于更多人更快上 ...
- asp.net core mvc视频A:笔记2-4.ActionResult(动作结果,即返回值)
json类型测试 方法一:实例化对象方式 代码 运行结果 方法二:封装方式 代码改动 运行结果 重点视图返回介绍,其他的不做介绍了 项目文件目录及文件添加 代码 运行结果 如果要显示的不是默认视图,可 ...