#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++ 读写注冊表,注冊文件图标关联的更多相关文章

  1. QSettings配置读写-win注册表操作-ini文件读写

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QSettings配置读写-win注册表操作-ini文件读写     本文地址:http:// ...

  2. Delphi 7使用自定义图标关联文件类型

    Delphi 7使用自定义图标关联文件类型 5.2 Delphi编程(40)  版权声明:本文为博主原创文章,未经博主允许不得转载. 在开发过程中,我们经常需要属于自己的文件类型,自定义的后缀名不仅可 ...

  3. QSettings读写注冊表、配置文件

    简述 普通情况下.我们在开发软件过程中,都会缓存一些信息到本地,能够使用轻量级数据库sqlite.也能够操作注冊表.读写配置文件. 关于QSettings的使用前面已经介绍过了.比較具体,见" ...

  4. C#注冊表操作汇总

    一.注冊表基本知识 1)       结构 键->项->子项->值项(名称.类型.数据) REG_SZ         字符串 REG_BINARY    二进制 REG_DWORD ...

  5. c++ 操作注冊表

    1.       注冊表简单介绍 注冊表是为Windows NT和Windows95中全部32位硬件/驱动和32位应用程序设计的数据文件,用于存储系统和应用程序的设置信息.16位驱动在Winnt (W ...

  6. YII用户注冊表单的实现熟悉前台各个表单元素操作方式

    模还是必须定义两个基本方法.还有部分label标签映射为汉字,假设进行表单验证,还要定义一些验证规则: <? php /* * 用户模型 * */ class user extends CAct ...

  7. C# 系统应用之注冊表使用具体解释

    在平时做项目时,我们有时会遇到注冊表的操作,比如前面我们须要获取IE浏览器地址栏的信息.获取"我的电脑"地址栏输入的目录信息.USB近期使用信息等.注冊表项是注冊表的基本组织单位, ...

  8. PLSQL Developer过期要注冊表

    打开执行输入 regedit 打表注冊表 删除 HKEY_CURRENT_USER\Software\Allround Automations HKEY_CURRENT_USER\Software\M ...

  9. 64位Windows操作系统中的注冊表

    x64系统上有x64.x86两种注冊表,记录下. 64 位Windows系统中的注冊表分为 32 位注冊表项和 64 位注冊表项.很多 32 位注冊表项与其对应的 64 位注冊表项同名. 在64位版本 ...

随机推荐

  1. ubuntu配置无密码登录

    1 本地生成ssh公钥和私钥, 2将公钥拷贝到ubuntu上的.ssh/authorized_keys 中

  2. Architecting Android…The clean way?

    Architecting Android-The clean way? 原文链接:http://fernandocejas.com/2014/09/03/architecting-android-th ...

  3. apache的order allow deny

    这个东西确实挺容易让我们迷糊.其实也不难,只要你掌握这样一条规律即可:首先举个例子: Order deny,allowdeny  from allallow from 127.0.0.1 我们判断的依 ...

  4. 【Hadoop】Hadoop MR异常处理

    1.代码示例 package com.ares.hadoop.mr.flowsort; import java.io.IOException; import org.apache.hadoop.con ...

  5. Nginx反向代理、负载均衡及日志

    Nginx反向代理.负载均衡及日志 1.原理图   2.正向代理与反向代理 (1)代理服务器 代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送给代理服务器,代理服务接受客户机请求之后 ...

  6. 解决dubbo问题:forbid consumer(1)

    原因: 1.dubbo服务没有起动起来 2.dubbo链接的地址出现异常 3.dubbo服务端更新了服务接口,没有发布 如果已上都没有问题,那么还有一个原因就是 “ 别人的代码有问题 阻碍了 你的程序 ...

  7. iOS音乐后台播放及锁屏信息显示

    实现音乐的后台播放.以及播放时,能够控制其暂停,下一首等操作,以及锁屏图片歌曲名等的显示 此实例须要真机调试.效果图例如以下: project下载:githubproject下载 实现步骤: 1.首先 ...

  8. linux 编译中required file `./ltmain.sh' not found 错误的解决办法(转)

    在linux下编译c/c++程序出错:$ automake --add-missing....configure.in:18: required file `build/ltmain.sh' not ...

  9. 使用浏览器地址栏调用CXF Webservice的写法

    /* * 通过url调用 * http://localhost:8080/EFP/webService/TestWebservice/testOut/arg0/liuyx */ http://loca ...

  10. CLR 完全介绍

    From: http://msdn.microsoft.com/zh-cn/magazine/cc164193.aspx http://msdn.microsoft.com/en-us/magazin ...