Index: src/ch/MainWnd.cpp =================================================================== diff -u -N -r328d5100c7f464a4b1fbbbd7ccfa07bf2aaae2cf -rc7c8665bac90c5701e577cd11acfad86538b8063 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 328d5100c7f464a4b1fbbbd7ccfa07bf2aaae2cf) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision c7c8665bac90c5701e577cd11acfad86538b8063) @@ -2085,14 +2085,21 @@ void CMainWnd::OnPopupRegisterdll() { + CString strPath; + CCopyHandlerApp* pApp = GetApp(); + if(pApp) + { + strPath = pApp->GetProgramPath(); + strPath += _T("\\"); + } + #ifdef _WIN64 - HRESULT hResult = RegisterShellExtDll(_T("chext64.dll"), true); + strPath += _T("chext64.dll"); #else - HRESULT hResult = RegisterShellExtDll(_T("chext.dll"), true); + strPath += _T("chext.dll"); #endif - if(SUCCEEDED(hResult)) - MsgBox(IDS_REGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); - else + HRESULT hResult = RegisterShellExtDll(strPath, true); + if(FAILED(hResult)) { TCHAR szStr[256], szText[768]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL); @@ -2101,18 +2108,28 @@ _sntprintf(szText, 768, GetResManager()->LoadString(IDS_REGISTERERR_STRING), hResult, szStr); AfxMessageBox(szText, MB_ICONERROR | MB_OK); } + else if(hResult == S_OK) + MsgBox(IDS_REGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); } void CMainWnd::OnPopupUnregisterdll() { + CString strPath; + CCopyHandlerApp* pApp = GetApp(); + if(pApp) + { + strPath = pApp->GetProgramPath(); + strPath += _T("\\"); + } + #ifdef _WIN64 - HRESULT hResult = RegisterShellExtDll(_T("chext64.dll"), false); + strPath += _T("chext64.dll"); #else - HRESULT hResult = RegisterShellExtDll(_T("chext.dll"), false); + strPath += _T("chext.dll"); #endif - if(SUCCEEDED(hResult)) - MsgBox(IDS_UNREGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); - else + + HRESULT hResult = RegisterShellExtDll(strPath, false); + if(FAILED(hResult)) { TCHAR szStr[256], szText[768]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL); @@ -2121,6 +2138,8 @@ _sntprintf(szText, 768, GetResManager()->LoadString(IDS_UNREGISTERERR_STRING), hResult, szStr); AfxMessageBox(szText, MB_ICONERROR | MB_OK); } + else if(hResult == S_OK) + MsgBox(IDS_UNREGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); } void CMainWnd::PrepareToExit() Index: src/ch/register.cpp =================================================================== diff -u -N -re667429b5d9008da845b7bd146a2581c38551dfd -rc7c8665bac90c5701e577cd11acfad86538b8063 --- src/ch/register.cpp (.../register.cpp) (revision e667429b5d9008da845b7bd146a2581c38551dfd) +++ src/ch/register.cpp (.../register.cpp) (revision c7c8665bac90c5701e577cd11acfad86538b8063) @@ -27,27 +27,53 @@ HRESULT RegisterShellExtDll(LPCTSTR lpszPath, bool bRegister) { - HRESULT hResult = CoInitialize(NULL); - if(FAILED(hResult)) - return hResult; - - HRESULT (STDAPICALLTYPE *pfn)(void); - HINSTANCE hMod = LoadLibrary(lpszPath); // load the dll - if(hMod == NULL) - hResult = HRESULT_FROM_WIN32(GetLastError()); - if(SUCCEEDED(hResult) && !hMod) - hResult = E_FAIL; + // first try - load dll and register it manually. + HRESULT hResult = S_OK; + // if failed - try by loading extension manually (would fail on vista when running as user) + hResult = CoInitialize(NULL); if(SUCCEEDED(hResult)) { - (FARPROC&)pfn = GetProcAddress(hMod, (bRegister ? "DllRegisterServer" : "DllUnregisterServer")); - if(pfn == NULL) + HRESULT (STDAPICALLTYPE *pfn)(void); + HINSTANCE hMod = LoadLibrary(lpszPath); // load the dll + if(hMod == NULL) + hResult = HRESULT_FROM_WIN32(GetLastError()); + if(SUCCEEDED(hResult) && !hMod) hResult = E_FAIL; if(SUCCEEDED(hResult)) - hResult = (*pfn)(); + { + (FARPROC&)pfn = GetProcAddress(hMod, (bRegister ? "DllRegisterServer" : "DllUnregisterServer")); + if(pfn == NULL) + hResult = E_FAIL; + if(SUCCEEDED(hResult)) + hResult = (*pfn)(); - CoFreeLibrary(hMod); + CoFreeLibrary(hMod); + } + CoUninitialize(); } - CoUninitialize(); + // if previous operation failed (ie. vista system) - try running regsvr32 with elevated privileges + if(SCODE_CODE(hResult) == ERROR_ACCESS_DENIED) + { + hResult = S_FALSE; + // try with regsvr32 + SHELLEXECUTEINFO sei; + memset(&sei, 0, sizeof(sei)); + sei.cbSize = sizeof(sei); + sei.fMask = SEE_MASK_UNICODE; + sei.lpVerb = _T("runas"); + sei.lpFile = _T("regsvr32.exe"); + CString strParams; + if(bRegister) + strParams = CString(_T(" \"")) + lpszPath + CString(_T("\"")); + else + strParams = CString(_T("/u \"")) + lpszPath + CString(_T("\"")); + sei.lpParameters = strParams; + sei.nShow = SW_SHOW; + + if(!ShellExecuteEx(&sei)) + hResult = E_FAIL; + } + return hResult; }