static HRESULT RegisterBho(const std::wstring& clsid) { ATL::CRegKey key; std::wstring bhoKey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\"; bhoKey += clsid; LSTATUS lStatus = key.Create(HKEY_LOCAL_MACHINE, bhoKey.c_str()); if (lStatus != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lStatus); } lStatus = key.SetStringValue(NULL, L"YBBHO"); if (lStatus != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lStatus); } lStatus = key.SetDWORDValue(L"NoExplorer",1); if (lStatus != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lStatus); } key.Close(); return S_OK; }
BOOL CNTEventLogSource::Install(LPCTSTR lpszLogName, LPCTSTR lpszSourceName, LPCTSTR lpszEventMessageFile, LPCTSTR pszEventCategoryMessageFile, LPCTSTR pszEventParameterMessageFile, DWORD dwTypesSupported, DWORD dwCategoryCount) { //Validate our parameters ATLASSUME(lpszLogName != NULL); ATLASSERT(_tcslen(lpszLogName)); ATLASSUME(lpszSourceName != NULL); ATLASSERT(_tcslen(lpszSourceName)); ATLASSUME(lpszEventMessageFile != NULL); //What will be the return value from this function, assume the worst BOOL bSuccess = FALSE; //Make the necessary updates to the registry TCHAR szKey[4096]; _stprintf_s(szKey, sizeof(szKey)/sizeof(TCHAR), _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s"), lpszLogName); ATL::CRegKey appKey; if (appKey.Create(HKEY_LOCAL_MACHINE, szKey) == ERROR_SUCCESS) { ATL::CRegKey sourceKey; if (sourceKey.Create(appKey, lpszSourceName, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL) == ERROR_SUCCESS) { //Write the EventMessageFile string value bSuccess = sourceKey.SetStringValue(_T("EventMessageFile"), lpszEventMessageFile) == ERROR_SUCCESS; //Write the TypesSupported value bSuccess = bSuccess && sourceKey.SetDWORDValue(_T("TypesSupported"), dwTypesSupported) == ERROR_SUCCESS; //Write the CategoryCount value if required if (dwCategoryCount && bSuccess) bSuccess = sourceKey.SetDWORDValue(_T("CategoryCount"), dwCategoryCount) == ERROR_SUCCESS; //Write the CategoryMessageFile string if required if (pszEventCategoryMessageFile && _tcslen(pszEventCategoryMessageFile) && bSuccess) bSuccess = sourceKey.SetStringValue(_T("CategoryMessageFile"), pszEventCategoryMessageFile) == ERROR_SUCCESS; //Write the ParameterMessageFile string if required if (pszEventParameterMessageFile && _tcslen(pszEventParameterMessageFile) && bSuccess) bSuccess = sourceKey.SetStringValue(_T("ParameterMessageFile"), pszEventParameterMessageFile) == ERROR_SUCCESS; //Update the sources registry key so that the event viewer can filter on the events which we write to the event log if (bSuccess) { CNTServiceStringArray sources; if (GetStringArrayFromRegistry(appKey, _T("Sources"), sources)) { //If our name is not in the array then add it BOOL bFoundMyself = FALSE; #ifdef CNTSERVICE_MFC_EXTENSIONS for (int i=0; i<sources.GetSize() && !bFoundMyself; i++) bFoundMyself = (sources.GetAt(i) == lpszSourceName); #else bFoundMyself = (std::find(sources.begin(), sources.end(), lpszSourceName) != sources.end()); #endif if (!bFoundMyself) { #ifdef CNTSERVICE_MFC_EXTENSIONS sources.Add(lpszSourceName); #else sources.push_back(lpszSourceName); #endif SetStringArrayIntoRegistry(appKey, _T("Sources"), sources); } } } } } return bSuccess; }
void AddinHelper::LaunchExe() { TSDEBUG4CXX("LaunchExe , enter Now = "<<::GetTickCount()); BOOL bFirst = TodayNotDo(); if (bFirst){ SendState::Send("explorerplugin_startup", "explorerplugin"); } else{ SendState::Send("explorerplugin_timer", "explorerplugin"); } //判断地域标志 DWORD dwLastUTC = 0; DWORD dwZoneAllow = 0; BOOL bCando = FALSE; ATL::CRegKey key; if (!bFirst && key.Open(HKEY_CURRENT_USER, REGEDITPATH) == ERROR_SUCCESS) { bCando = TRUE; if (key.QueryDWORDValue(ZONESWITCH, dwZoneAllow) != ERROR_SUCCESS || dwZoneAllow != 1){ bCando = FALSE; } else if(key.QueryDWORDValue(LASTLAUNCHUTC, dwLastUTC) == ERROR_SUCCESS) { __time64_t tTime = (__time64_t)dwLastUTC; tm* pTm = _localtime64(&tTime); LONG nLastDay = pTm->tm_mday; LONG nLastMonth = pTm->tm_mon; LONG nLastYear = pTm->tm_year; __time64_t lCurTime; _time64( &lCurTime); tm* pTmc = _localtime64(&lCurTime); LONG nCurDay = pTmc->tm_mday; LONG nCurMonth = pTmc->tm_mon; LONG nCurYear = pTmc->tm_year; TSDEBUG4CXX("check time pTmc = "<<nCurYear<<nCurMonth<<nCurDay<<", pTm = "<<nLastYear<<nLastMonth<<nLastDay); if (nCurDay == nLastDay && nCurMonth == nLastMonth && nCurYear == nLastYear){ bCando = FALSE; } else{ bCando = TRUE; } } key.Close(); } TSDEBUG4CXX("LaunchExe , bCando = "<<bCando); if (!bFirst && !bCando){ return; } if (!bFirst && IsStartUp()){ return; } RegData rd = QueryRegVal(HKEY_LOCAL_MACHINE, REGEDITPATH, _T("Path"), KEY_READ | KEY_WOW64_32KEY); TSDEBUG4CXX("LaunchExe rd.strData = "<<rd.strData.c_str()); if (rd.strData == L"" || !PathFileExists(rd.strData.c_str())){ return; } TCHAR* tszProName = PathFindFileName(rd.strData.c_str()); if (!bFirst && QueryProcessExist(tszProName)){ TSDEBUG4CXX("LaunchExe process exist "<<tszProName); return; } SHELLEXECUTEINFO sei; std::memset(&sei, 0, sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.lpFile = rd.strData.c_str(); sei.lpParameters = L"/sstartfrom explorerplugin /embedding"; sei.nShow = SW_SHOWNORMAL; ShellExecuteEx(&sei); TSDEBUG4CXX("LaunchExe rd.strData.c_str() = "<<rd.strData.c_str()); if (bFirst){ ATL::CRegKey key; if (key.Open(HKEY_CURRENT_USER, REGEDITPATH) == ERROR_SUCCESS) { __time64_t lCurTime; _time64( &lCurTime); key.SetDWORDValue(L"pluginlastutc", lCurTime); key.Close(); } } }