00001
00002
00003
00004 #pragma once
00005
00006 #ifndef __AFXWIN_H__
00007 #error include 'stdafx.h' before including this file for PCH
00008 #endif
00009
00010 #include "resource.h"
00011 #include <vector>
00012 #include "MgaUtil.h"
00013
00014 typedef jint (JNICALL *P_JNI_CreateJavaVM) (JavaVM **pvm, void** penv, void *args);
00015 typedef jint (JNICALL *P_JNI_GetCreatedJavaVMs) (JavaVM **vmBuf,jsize bufLen, jsize *nVMs);
00016
00018
00019
00020
00021
00022 class CComponentApp : public CWinApp
00023 {
00024 public:
00025 CComponentApp();
00026
00027 void addComponents( HKEY folder );
00028
00029
00030
00031
00032 public:
00033 virtual BOOL InitInstance();
00034
00035
00036 virtual int ExitInstance();
00037
00038
00039
00040
00041
00042 DECLARE_MESSAGE_MAP()
00043
00044
00045
00046 public:
00047 std::vector<COleObjectFactory*> m_factories;
00048 };
00049
00050
00052
00053
00054
00055
00056
00057
00058 class CUACUtils
00059 {
00060 public:
00061
00062
00063 #ifndef BCM_FIRST
00064 static const DWORD BCM_FIRST = 0x1600;
00065 #endif
00066 #ifndef BCM_SETSHIELD
00067 static const DWORD BCM_SETSHIELD = (BCM_FIRST + 0x000C);
00068 #endif
00069
00070 static bool isVistaOrLater()
00071 {
00072 OSVERSIONINFO osvi;
00073
00074 ::ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
00075 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00076
00077 GetVersionEx(&osvi);
00078
00079 return (osvi.dwMajorVersion >= 6);
00080 }
00081
00082 static bool isElevated()
00083 {
00084 if ( !isVistaOrLater() ) {
00085 return true;
00086 }
00087
00088 HANDLE hToken = NULL;
00089
00090 if ( !::OpenProcessToken(
00091 ::GetCurrentProcess(),
00092 TOKEN_QUERY,
00093 &hToken ) )
00094 {
00095 return false;
00096 }
00097
00098 DWORD dwReturnLength = 0;
00099 TOKEN_ELEVATION te;
00100 ::ZeroMemory(&te, sizeof(te));
00101
00102 if ( ::GetTokenInformation(
00103 hToken,
00104 TokenElevation,
00105 &te,
00106 sizeof(te),
00107 &dwReturnLength ) )
00108 {
00109 ASSERT( dwReturnLength == sizeof( te ) );
00110 return (te.TokenIsElevated != 0);
00111 }
00112
00113 ::CloseHandle( hToken );
00114
00115 return false;
00116 }
00117
00118 template <typename T>
00119 static HRESULT CreateElevatedInstance(LPCOLESTR progId,
00120 T** object, HWND window = 0)
00121 {
00122 CLSID clsId;
00123 HRESULT hr = ::CLSIDFromProgID(progId, &clsId);
00124 if (FAILED(hr)) {
00125 return hr;
00126 }
00127
00128 return CreateElevatedInstance(clsId, object, window);
00129 }
00130
00131 template <typename T>
00132 static HRESULT CreateElevatedInstance(REFCLSID classId,
00133 T** object, HWND window = 0)
00134 {
00135 BIND_OPTS3 bindOptions;
00136 gettokeninformation
00137 ::ZeroMemory(&bindOptions, sizeof (BIND_OPTS3));
00138 bindOptions.cbStruct = sizeof (BIND_OPTS3);
00139 bindOptions.hwnd = window;
00140 bindOptions.dwClassContext = CLSCTX_LOCAL_SERVER;
00141
00142 WCHAR wszMonikerName[300];
00143 WCHAR wszCLSID[50];
00144
00145 #define cntof(a) (sizeof(a)/sizeof(a[0]))
00146
00147 ::StringFromGUID2(classId, wszCLSID,
00148 cntof(wszCLSID));
00149
00150 HRESULT hr = ::StringCchPrintfW(wszMonikerName, cntof(wszMonikerName), L"Elevation:Administrator!new:%s", wszCLSID);
00151
00152 if (FAILED(hr))
00153 {
00154 return hr;
00155 }
00156
00157 return ::CoGetObject(wszMonikerName,
00158 &bindOptions,
00159 __uuidof(T),
00160 reinterpret_cast<void**>(object));
00161 }
00162
00163 static void SetShieldIcon(const CButton& button, bool on=true)
00164 {
00165 button.SendMessage(BCM_SETSHIELD, 0, on ? TRUE : FALSE);
00166 }
00167 };
00168
00169
00170 class CComponentReg
00171 {
00172 public:
00173 CComponentReg();
00174
00175 CStringList paradigms;
00176 HRESULT RegisterParadigms(regaccessmode_enum loc = REGACCESS_USER);
00177 HRESULT UnregisterParadigms(regaccessmode_enum loc = REGACCESS_USER);
00178 };