您的位置:首页 > 其它

WIN7/XP用注册表关联指定后缀名和打开程序(C程序实现)

2012-08-07 16:00 351 查看
在前一篇文章中/article/1847954.html,已经介绍了用注册表关联指定的后缀名和打开程序的原理,而且了详细的手动操作过程。本文通过C程序实现上文的关联功能。

本文的完整代码在http://download.csdn.net/detail/arvon2012/4482694

对刚接触注册表编程的朋友请看入门文章/article/1847950.html

这里其实就是用代码模拟手工操作,完全一样的步骤实现关联。有什么意见欢迎留言!谢谢!



步骤:

1.创建后缀键,并给后缀键传入默认值,设置好处理键

//create .seve
	if (ERROR_SUCCESS!=RegCreateKey(HKEY_CLASSES_ROOT,L".seve",&hKey))
    {
        printf("创建子键失败!\n");
        return 0;
    }
    else
    {
        printf("create .seve!\n");
    }
	RegCloseKey(hKey);
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT,L".arv",0,KEY_ALL_ACCESS,&hKey)!=ERROR_SUCCESS) 
    {
        printf("创建HKEY失败!\n");
        return 0;
    }
	//set value
	LPCWSTR szValueName1 = L"";
	LPCWSTR szValueDate1=L"seven";
	UINT cbLen=wcslen(szValueDate1);
	if(RegSetValueExW(hKey,NULL,0,REG_SZ,(const unsigned char *)szValueDate1,cbLen*2)==ERROR_SUCCESS)
    {
        printf("set value!\n");
    }
    else
    {
        printf("创建REG_SZ键值失败!\n");
        return 0;
    }
	RegCloseKey(hKey);



2.创建处理键,并设置打开程序

//create opofile
	if (ERROR_SUCCESS!=RegCreateKey(HKEY_CLASSES_ROOT,L"opofile\\shell\\open\\command",&hKey))
    {
        printf("创建子键失败!\n");
        return 0;
    }
    else
    {
        printf("create opofile!\n");
    }
	szValueDate1=L"\"F:\\SRC\\FILTER\\JUMP\\Debug\\JUMP.exe\" \"%1\"";
	cbLen=wcslen(szValueDate1);
	if(RegSetValueExW(hKey,NULL,0,REG_SZ,(const unsigned char *)szValueDate1,cbLen*2)==ERROR_SUCCESS)
    {
        printf("set opofile value!\n");
    }
    else
    {
        printf("创建REG_SZ键值失败!\n");
        return 0;
    }
	RegCloseKey(hKey);
	getchar();


技术相关更多文章猛击:哇啦天堂论坛技术区
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐