WIN7/XP用註冊表關聯指定後綴名和打開程序(C程序實現)

前一篇文章http://blog.csdn.net/arvon2012/article/details/7818909已經介紹了用註冊表關聯指定的後綴名和打開程序的原理,而且了詳細的手動操作過程。本文通過C程序實現上文的關聯功能。

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

對剛接觸註冊表編程的朋友請看入門文章http://blog.csdn.net/arvon2012/article/details/7839659

這裏其實就是用代碼模擬手工操作,完全一樣的步驟實現關聯。有什麼意見歡迎留言!謝謝!

 

步驟:

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();


技術相關更多文章猛擊:哇啦天堂論壇技術區
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章