Guest User

Untitled

a guest
Mar 26th, 2012
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     wchar_t arrayArg[65535];
  2.     int size_lenght;
  3.     // first try - load dll and register it manually.
  4.     HRESULT hResult = S_OK;
  5.     // if failed - try by loading extension manually (would fail on vista when running as user)
  6.     hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  7.     if(SUCCEEDED(hResult))
  8.     {
  9.         HRESULT (STDAPICALLTYPE *pfn)(void);
  10.         size_lenght=dllPath.toWCharArray(arrayArg);
  11.         HINSTANCE hMod = LoadLibrary(arrayArg); // load the dll
  12.         if(hMod == NULL)
  13.             hResult = HRESULT_FROM_WIN32(GetLastError());
  14.         if(SUCCEEDED(hResult) && !hMod)
  15.             hResult = E_FAIL;
  16.         if(SUCCEEDED(hResult))
  17.         {
  18.             (FARPROC&)pfn = GetProcAddress(hMod, (bRegister ? "DllRegisterServer" : "DllUnregisterServer"));
  19.             if(pfn == NULL)
  20.                 hResult = E_FAIL;
  21.             if(SUCCEEDED(hResult))
  22.                 hResult = (*pfn)();
  23.  
  24.             CoFreeLibrary(hMod);
  25.         }
  26.         CoUninitialize();
  27.         if(SUCCEEDED(hResult) && SCODE_CODE(hResult) != ERROR_ACCESS_DENIED)
  28.             return true;
  29.     }
  30.    
  31.     ////////////////////////////// Second way to load //////////////////////////////
  32.     QStringList arguments;
  33.     arguments.append("/s");
  34.     if(!bRegister)
  35.         arguments.append("/u");
  36.     arguments.append(dllPath);
  37.     QString argumentsString;
  38.     for (int i = 0; i < arguments.size(); ++i) {
  39.         if(argumentsString.isEmpty())
  40.             argumentsString+=arguments.at(i);
  41.         else
  42.             if(i == arguments.size())
  43.                 argumentsString+=" \""+arguments.at(i)+"\"";
  44.             else
  45.                 argumentsString+=' '+arguments.at(i);
  46.     }
  47.     int result=QProcess::execute("regsvr32",arguments);
  48.     bool ok=false;
  49.     if(result==0)
  50.         ok=true;
  51.     if(result==5)
  52.     {
  53.         if(!quiet)
  54.         {
  55.             ////////////////////////////// Last way to load //////////////////////////////
  56.             // try with regsvr32, win32 because for admin dialog
  57.  
  58.             size_lenght=argumentsString.toWCharArray(arrayArg);
  59.             //size_lenght*sizeof(wchar_t)
  60.             wcscpy(arrayArg+size_lenght*sizeof(wchar_t),TEXT("\0"));
  61.             SHELLEXECUTEINFO sei;
  62.             memset(&sei, 0, sizeof(sei));
  63.             sei.cbSize = sizeof(sei);
  64.             sei.fMask = SEE_MASK_UNICODE;
  65.             sei.lpVerb = TEXT("runas");
  66.             sei.lpFile = TEXT("regsvr32.exe");
  67.             sei.lpParameters = arrayArg;
  68.             sei.nShow = SW_SHOW;
  69.             ok=ShellExecuteEx(&sei);
  70.         }
  71.     }
RAW Paste Data