我試圖找到使用註冊表的Excel的路徑,並試圖調整我在互聯網上找到的一些代碼。我正在使用64位Win7,並確認使用regedit的關鍵在那裏。試圖通過搜索註冊表找到excel的路徑
#include <windows.h>
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
HKEY hKey = 0;
char buf[255] = {0};
DWORD dwType = 0;
DWORD dwBufSize = sizeof(buf);
const char* subkey = "SOFTWARE\\Classes\\Excel.Application\\CLSID";
if(RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS)
{
dwType = REG_SZ;
if(RegQueryValueEx(hKey,"default",0, &dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS)
{
cout << "key value is '" << buf << "'\n";
}
else
cout << "can not query for key value\n";
RegCloseKey(hKey);
}
else
cout << "Can not open key\n";
cin.ignore();
return 0;
}
有誰知道這是爲什麼不工作? 謝謝 James
執行程序時會發生什麼錯誤消息。 – vikky 2012-02-06 12:51:18
你的程序是32位還是64位? – 2012-02-06 13:34:45
它是64位的,問題不在於出現錯誤「RegOpenKey」沒有設置hKey。 – James 2012-02-06 16:07:39