BOOL CComCatCachedCategory::LoadFromRegistry() { WCHAR bufKey[MAX_PATH]; WCHAR guidStr[MAX_PATH]; DWORD dataSize, i; CComHeapPtr<CATCACHEHDR> buffer; GUID *guidArray; if (!fLocalDsa) return FALSE; dataSize = 0; if (!StringFromGUID2(fCategory, guidStr, MAX_PATH)) return FALSE; wsprintf(bufKey, L"%s\\%s\\%s", REGPATH , guidStr, L"Enum"); // Try to read key and get proper value size if (SHGetValue(HKEY_CURRENT_USER, bufKey, IMPLEMENTING, NULL, NULL, &dataSize)) return FALSE; buffer.Attach((PCATCACHEHDR)CoTaskMemAlloc(dataSize)); SHGetValue(HKEY_CURRENT_USER, bufKey, IMPLEMENTING, NULL, buffer, &dataSize); guidArray = (GUID*)(buffer + 1); for (i = 0; i < buffer->classCount; i++) { // Add class to cache DSA_InsertItem(fLocalDsa, DSA_APPEND, guidArray + i); } return TRUE; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 弹出菜单初始化 VOID CMainWnd::OnMenuPopup(WPARAM wParam, LPARAM lParam) { HWND hWnd; DWORD dwSize; TCHAR tzTemp[512]; TCHAR tzPath[512]; switch (GetMenuItemID((HMENU) wParam, 0)) { case IDM_Help_Desktop: // 判断快捷方式是否存在 CheckCommand(IDM_Help_Desktop, CShortcut::Exist(CSIDL_DESKTOP)); CheckCommand(IDM_Help_StartMenu, CShortcut::Exist(CSIDL_STARTMENU)); CheckCommand(IDM_Help_ProgramMenu, CShortcut::Exist(CSIDL_PROGRAMS)); CheckCommand(IDM_Help_QuickLaunch, CShortcut::Exist(CSIDL_APPDATA)); CheckCommand(IDM_Help_VisualStudio, CVSTool::Exist()); break; case IDM_Play_Play: hWnd = CClientWnd::GetActive(); _ExIf(hWnd, SendMessage(hWnd, WM_INITMENUPOPUP, wParam, lParam)); break; case IDM_View_Toolbar: GetModuleFileName(NULL, tzTemp, MAX_PATH); wsprintf(tzPath, TEXT("\"%s\" \"%%1\""), tzTemp); dwSize = _NumOf(tzTemp); SHGetValue(HKEY_CLASSES_ROOT, STR_AppName TEXT("\\shell\\open\\command"), NULL, NULL, tzTemp, &dwSize); CheckCommand(IDM_View_AssociateFile, lstrcmpi(tzTemp, tzPath) == 0); break; } }
/* =================================================== * CRegEntry::SetMulti(LPCTSTR lpszValue, size_t nLen, bool bInternal) * * Stores an array of null-terminated string, terminated by two null characters. * For Example: First String\0Second\Third\0\0 * * Important Params: * * LPCTSTR lpszValue: The string consisting of the null-terminated string array * size_t nLen: The number of characters in the string, including null characters * * Note: For inserting individual null-terminated strings into the array, * use MultiAdd or MultiSetAt. */ BOOL ReadRegMString( HKEY hkey, LPCTSTR pszSubKey, LPCTSTR pszValue, CSimpleArray<CString> &ms ) { DWORD dwBuffer = _MAX_REG_VALUE; DWORD dwType = REG_MULTI_SZ; TCHAR *pbuf = new TCHAR[_MAX_REG_VALUE]; if( pbuf && ERROR_SUCCESS==SHGetValue(hkey, pszSubKey, pszValue, &dwType, pbuf, &dwBuffer) ) { size_t nCur = 0, nPrev = 0, nShortLen = dwBuffer/sizeof(TCHAR); if( nShortLen>2 ) { if (*(pbuf + nShortLen-1) == '\0') nShortLen--; while( (nCur = (int)(_tcschr(pbuf+nPrev, '\0')-pbuf)) < nShortLen ) { ms.Add( pbuf+nPrev ); nPrev = nCur+1; } } return TRUE; } return FALSE; }
bool IsRunningLimited() { LPCTSTR pszSubKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"); LPCTSTR pszValue = _T("EnableLUA"); DWORD dwType = 0; DWORD dwValue = 0; DWORD dwValueSize = sizeof(DWORD); if(ERROR_SUCCESS != SHGetValue(HKEY_LOCAL_MACHINE, pszSubKey, pszValue, &dwType, &dwValue, &dwValueSize)) { //failed to read the reg key, either it's not there or we don't have access to the registry //If we are vista then assume we don't have access and we are running as a limited app //otherwise we are xp and the reg key probably doesn't exist and we are not a limited running app if(IsVista()) { OutputDebugString(_T("Ditto - Failed to read registry entry finding UAC, Running as limited application")); return true; } } if(dwValue == 1) { OutputDebugString(_T("Ditto - UAC ENABLED, Running as limited application")); return true; } OutputDebugString(_T("Ditto - Running as standard application")); return false; }
static inline void addPluginPathsFromRegistry(HKEY rootKey, HashSet<String>& paths) { HKEY key; HRESULT result = RegOpenKeyExW(rootKey, L"Software\\MozillaPlugins", 0, KEY_ENUMERATE_SUB_KEYS, &key); if (result != ERROR_SUCCESS) return; wchar_t name[128]; FILETIME lastModified; // Enumerate subkeys for (int i = 0;; i++) { DWORD nameLen = _countof(name); result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified); if (result != ERROR_SUCCESS) break; WCHAR pathStr[_MAX_PATH]; DWORD pathStrSize = sizeof(pathStr); DWORD type; result = SHGetValue(key, name, TEXT("Path"), &type, (LPBYTE)pathStr, &pathStrSize); if (result != ERROR_SUCCESS || type != REG_SZ) continue; paths.add(String(pathStr, pathStrSize / sizeof(WCHAR) - 1)); } RegCloseKey(key); }
bool GetRegistryDword(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, DWORD* data) { DWORD type; DWORD dataSize = sizeof(DWORD); return (SHGetValue(rootKey, subKey, value, &type, data, &dataSize) == ERROR_SUCCESS && type == REG_DWORD); }
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // LSActivateActCtxForClsid // Activates the custom activation context for the specified CLSID // HANDLE LSActivateActCtxForClsid(REFCLSID rclsid, PULONG_PTR pulCookie) { HANDLE hContext = INVALID_HANDLE_VALUE; TCHAR szCLSID[39] = { 0 }; // // Get the DLL that implements the COM object in question // if (SUCCEEDED(CLSIDToString(rclsid, szCLSID, COUNTOF(szCLSID)))) { TCHAR szSubkey[MAX_PATH] = { 0 }; HRESULT hr = StringCchPrintf(szSubkey, COUNTOF(szSubkey), _T("CLSID\\%ls\\InProcServer32"), szCLSID); if (SUCCEEDED(hr)) { TCHAR szDll[MAX_PATH] = { 0 }; DWORD cbDll = sizeof(szDll); LONG lres = SHGetValue( HKEY_CLASSES_ROOT, szSubkey, NULL, NULL, szDll, &cbDll); if (lres == ERROR_SUCCESS) { // // Activate the custom manifest (if any) of that DLL // hContext = LSActivateActCtxForDll(szDll, pulCookie); } } } return hContext; }
HRESULT CBandSiteMenu::_CreateMenuPart() { WCHAR wszBandName[MAX_PATH]; WCHAR wszBandGUID[MAX_PATH]; WCHAR wRegKey[MAX_PATH]; UINT cBands; DWORD dwDataSize; CATID category = CATID_DeskBand; HMENU hmenuToolbars; DWORD dwRead; CComPtr<IEnumGUID> pEnumGUID; HRESULT hr; if (m_hmenu) DestroyMenu(m_hmenu); /* Load the template we will fill in */ m_hmenu = LoadMenuW(GetModuleHandleW(L"browseui.dll"), MAKEINTRESOURCEW(IDM_TASKBAR_TOOLBARS)); if (!m_hmenu) return HRESULT_FROM_WIN32(GetLastError()); /* Get the handle of the submenu where the available items will be shown */ hmenuToolbars = GetSubMenu(m_hmenu, 0); /* Create the category enumerator */ hr = SHEnumClassesOfCategories(1, &category, 0, NULL, &pEnumGUID); if (FAILED_UNEXPECTEDLY(hr)) return hr; m_ComCatGuids.RemoveAll(); /* Enumerate the classes in the CATID_DeskBand category */ cBands = 0; do { GUID iter; pEnumGUID->Next(1, &iter, &dwRead); if (!dwRead) continue; if (!StringFromGUID2(iter, wszBandGUID, MAX_PATH)) continue; /* Get the band name */ StringCchPrintfW(wRegKey, MAX_PATH, L"CLSID\\%s", wszBandGUID); dwDataSize = MAX_PATH; SHGetValue(HKEY_CLASSES_ROOT, wRegKey, NULL, NULL, wszBandName, &dwDataSize); /* Insert it */ InsertMenu(hmenuToolbars, cBands, MF_BYPOSITION, m_ComCatGuids.GetSize() + FIRST_COMCAT_MENU_ID, wszBandName); m_ComCatGuids.Add(iter); cBands++; } while (dwRead > 0); return S_OK; }
BOOL ReadRegString(HKEY hkey, LPCTSTR pszSubKey, LPCTSTR pszValue, CString &str) { TCHAR szBuffer[MAX_PATH] = {0}; DWORD dwBuffer = MAX_PATH; DWORD dwType = REG_SZ; BOOL bRet = ERROR_SUCCESS==SHGetValue( hkey, pszSubKey, pszValue, &dwType, szBuffer, &dwBuffer ); str = szBuffer; return bRet; }
// thanks to ZeekyHBomb :) std::string ObtainSteamFolder() { char buf[MAX_PATH]; DWORD buf_length = sizeof(buf); DWORD type = REG_SZ; if(SHGetValue(HKEY_CURRENT_USER, TEXT("Software\\Valve\\Steam"), TEXT("SteamPath"), &type, buf, &buf_length) != ERROR_SUCCESS) ShowError("No Steam-directory found (HKEY_CURRENT_USER\\Software\\Valve\\Steam\\SteamPath).\n"); return buf; }
static inline void addQuickTimePluginDirectory(Vector<String>& directories) { DWORD type; WCHAR installationDirectoryStr[_MAX_PATH]; DWORD installationDirectorySize = sizeof(installationDirectoryStr); HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Apple Computer, Inc.\\QuickTime"), TEXT("InstallDir"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize); if (result == ERROR_SUCCESS && type == REG_SZ) { String pluginDir = String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1) + "\\plugins"; directories.append(pluginDir); } }
/** * @brief Write archive support stuff */ void CConfigLog::WriteArchiveSupport() { DWORD registered = VersionOf7z(FALSE); DWORD standalone = VersionOf7z(TRUE); TCHAR path[MAX_PATH]; DWORD type = 0; DWORD size = sizeof path; WriteItem(0, _T("Archive support")); WriteItem(1, _T("Enable"), AfxGetApp()->GetProfileInt(_T("Merge7z"), _T("Enable"), 0)); wsprintf(path, _T("%u.%02u"), UINT HIWORD(registered), UINT LOWORD(registered)); WriteItem(1, _T("7-Zip software installed on your computer"), path); static const TCHAR szSubKey[] = _T("Software\\7-Zip"); static const TCHAR szValue[] = _T("Path"); SHGetValue(HKEY_LOCAL_MACHINE, szSubKey, szValue, &type, path, &size); WriteVersionOf7z(path); wsprintf(path, _T("%u.%02u"), UINT HIWORD(standalone), UINT LOWORD(standalone)); WriteItem(1, _T("7-Zip components for standalone operation"), path); GetModuleFileName(0, path, countof(path)); LPTSTR pattern = PathFindFileName(path); PathRemoveFileSpec(path); WriteVersionOf7z(path); WriteItem(1, _T("Merge7z plugins on path")); lstrcpy(pattern, _T("Merge7z*.dll")); WriteVersionOf(2, path); // now see what's on the path: if (DWORD cchPath = GetEnvironmentVariable(_T("path"), 0, 0)) { static const TCHAR cSep[] = _T(";"); LPTSTR pchPath = new TCHAR[cchPath]; GetEnvironmentVariable(_T("PATH"), pchPath, cchPath); LPTSTR pchItem = pchPath; while (int cchItem = StrCSpn(pchItem += StrSpn(pchItem, cSep), cSep)) { if (cchItem < MAX_PATH) { CopyMemory(path, pchItem, cchItem*sizeof*pchItem); path[cchItem] = 0; PathAppend(path, _T("Merge7z*.dll")); WriteVersionOf(2, path); } pchItem += cchItem; } delete[] pchPath; } }
static BOOL RemoveMyDriver() { char buf[300]; DWORD usagecount; DWORD valtype, valsize, rc; /* most of this is equivalent to what SQLRemoveDriver is suppposed to do, except that it consistently causes a crash, so we do it ourselves */ snprintf(buf, sizeof(buf), "SOFTWARE\\ODBC\\ODBCINST.INI\\%s", DriverName); valsize = sizeof(usagecount); usagecount = 0; valtype = REG_DWORD; rc = SHGetValue(HKEY_LOCAL_MACHINE, buf, "UsageCount", &valtype, &usagecount, &valsize); if (rc == ERROR_FILE_NOT_FOUND) { /* not installed, do nothing */ exit(0); } if (rc != ERROR_SUCCESS) { ProcessSysErrorMessage(rc, "one"); return FALSE; } if (usagecount > 1) { usagecount--; rc = SHSetValue(HKEY_LOCAL_MACHINE, buf, "UsageCount", REG_DWORD, &usagecount, sizeof(usagecount)); if (rc != ERROR_SUCCESS) { ProcessSysErrorMessage(rc, "two"); return FALSE; } return TRUE; } rc = SHDeleteKey(HKEY_LOCAL_MACHINE, buf); if (rc != ERROR_SUCCESS) { ProcessSysErrorMessage(rc, "three"); return FALSE; } rc = SHDeleteValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers", DriverName); if (rc != ERROR_SUCCESS) { ProcessSysErrorMessage(rc, "four"); return FALSE; } return TRUE; }
static String mimeTypeForExtension(const String& extension) { String ext = "." + extension; WCHAR contentTypeStr[256]; DWORD contentTypeStrLen = sizeof(contentTypeStr); DWORD keyType; HRESULT result = SHGetValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination(), L"Content Type", &keyType, (LPVOID)contentTypeStr, &contentTypeStrLen); if (result == ERROR_SUCCESS && keyType == REG_SZ) return String(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1); return String(); }
int CSetOverlayHandlers::GetInstalledOverlays() { // if there are more than 12 overlay handlers installed, then that means not all // of the overlay handlers can be shown. Windows chooses the ones first // returned by RegEnumKeyEx() and just drops the ones that come last in // that enumeration. int nInstalledOverlayhandlers = 0; // scan the registry for installed overlay handlers HKEY hKey; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers"), 0, KEY_ENUMERATE_SUB_KEYS, &hKey)==ERROR_SUCCESS) { TCHAR value[2048] = { 0 }; TCHAR keystring[2048] = { 0 }; for (int i = 0, rc = ERROR_SUCCESS; rc == ERROR_SUCCESS; i++) { DWORD size = _countof(value); FILETIME last_write_time; rc = RegEnumKeyEx(hKey, i, value, &size, NULL, NULL, NULL, &last_write_time); if (rc == ERROR_SUCCESS) { for (int j = 0; value[j]; ++j) { value[j] = (wchar_t)towlower(value[j]); } if (wcsstr(&value[0], L"tortoise") == 0) { // check if there's a 'default' entry with a guid _tcscpy_s(keystring, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers\\")); _tcscat_s(keystring, value); DWORD dwType = 0; DWORD dwSize = _countof(value); // the API docs only specify "The size of the destination data buffer", // but better be safe than sorry using _countof instead of sizeof if (SHGetValue(HKEY_LOCAL_MACHINE, keystring, NULL, &dwType, value, &dwSize) == ERROR_SUCCESS) { if ((dwSize > 10)&&(value[0] == '{')) nInstalledOverlayhandlers++; } } } } RegCloseKey(hKey); } return nInstalledOverlayhandlers; }
LRESULT CALLBACK CWindow::stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CWindow * pWnd = nullptr; if (uMsg == WM_NCCREATE) { // get the pointer to the window from lpCreateParams which was set in CreateWindow SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)((LPCREATESTRUCT(lParam))->lpCreateParams)); } // get the pointer to the window pWnd = GetObjectFromWindow(hwnd); // if we have the pointer, go to the message handler of the window // else, use DefWindowProc if (pWnd) { switch (uMsg) { case WM_ACTIVATE: if ((wParam == WA_ACTIVE)&&(!pWnd->bWindowRestored)&&(!pWnd->sRegistryPath.empty())) { WINDOWPLACEMENT wpl = {0}; DWORD size = sizeof(wpl); if (SHGetValue(HKEY_CURRENT_USER, pWnd->sRegistryPath.c_str(), pWnd->sRegistryValue.c_str(), REG_NONE, &wpl, &size) == ERROR_SUCCESS) SetWindowPlacement(hwnd, &wpl); else ShowWindow(hwnd, SW_SHOW); pWnd->bWindowRestored = true; } break; case WM_CLOSE: if (!pWnd->sRegistryPath.empty()) { WINDOWPLACEMENT wpl = {0}; wpl.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hwnd, &wpl); SHSetValue(HKEY_CURRENT_USER, pWnd->sRegistryPath.c_str(), pWnd->sRegistryValue.c_str(), REG_NONE, &wpl, sizeof(wpl)); } break; } return pWnd->WinMsgHandler(hwnd, uMsg, wParam, lParam); } else return DefWindowProc(hwnd, uMsg, wParam, lParam); }
BOOL CRegistryKey::IsKeyExistValue( HKEY hRoot, LPCTSTR lpKey, LPCTSTR lpValue ) { if ( lpKey == NULL || lpValue == NULL ) return FALSE; if ( _tcslen(lpKey)==0 || _tcslen(lpValue) == 0 ) return FALSE; DWORD dwSize = 0; DWORD dwType = 0; LONG nRet = SHGetValue(hRoot, lpKey, lpValue, &dwType, NULL, &dwSize); if ( nRet == ERROR_SUCCESS || nRet == ERROR_MORE_DATA ) return TRUE; return FALSE; }
static inline void addWindowsMediaPlayerPluginDirectory(Vector<String>& directories) { // The new WMP Firefox plugin is installed in \PFiles\Plugins if it can't find any Firefox installs WCHAR pluginDirectoryStr[_MAX_PATH + 1]; DWORD pluginDirectorySize = ::ExpandEnvironmentStringsW(TEXT("%SYSTEMDRIVE%\\PFiles\\Plugins"), pluginDirectoryStr, _countof(pluginDirectoryStr)); if (pluginDirectorySize > 0 && pluginDirectorySize <= _countof(pluginDirectoryStr)) directories.append(String(pluginDirectoryStr, pluginDirectorySize - 1)); DWORD type; WCHAR installationDirectoryStr[_MAX_PATH]; DWORD installationDirectorySize = sizeof(installationDirectoryStr); HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\MediaPlayer"), TEXT("Installation Directory"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize); if (result == ERROR_SUCCESS && type == REG_SZ) directories.append(String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1)); }
static inline void addAdobeAcrobatPluginDirectory(Vector<String>& directories) { HKEY key; HRESULT result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Adobe\\Acrobat Reader"), 0, KEY_READ, &key); if (result != ERROR_SUCCESS) return; WCHAR name[128]; FILETIME lastModified; Vector<int> latestAcrobatVersion; String latestAcrobatVersionString; // Enumerate subkeys for (int i = 0;; i++) { DWORD nameLen = sizeof(name) / sizeof(WCHAR); result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified); if (result != ERROR_SUCCESS) break; Vector<int> acrobatVersion = parseVersionString(String(name, nameLen)); if (compareVersions(acrobatVersion, latestAcrobatVersion)) { latestAcrobatVersion = acrobatVersion; latestAcrobatVersionString = String(name, nameLen); } } if (!latestAcrobatVersionString.isNull()) { DWORD type; WCHAR acrobatInstallPathStr[_MAX_PATH]; DWORD acrobatInstallPathSize = sizeof(acrobatInstallPathStr); String acrobatPluginKeyPath = "Software\\Adobe\\Acrobat Reader\\" + latestAcrobatVersionString + "\\InstallPath"; result = SHGetValue(HKEY_LOCAL_MACHINE, acrobatPluginKeyPath.charactersWithNullTermination(), 0, &type, (LPBYTE)acrobatInstallPathStr, &acrobatInstallPathSize); if (result == ERROR_SUCCESS) { String acrobatPluginDirectory = String(acrobatInstallPathStr, acrobatInstallPathSize / sizeof(WCHAR) - 1) + "\\browser"; directories.append(acrobatPluginDirectory); } } RegCloseKey(key); }
DLLEXPORT STDAPI DllRegisterServer(VOID) { if (!EnsureRegKey(g_lpRegKey)) return E_UNEXPECTED; WCHAR szPath[MAX_PATH]; GetModuleFileName(g_hInstance, szPath, MAX_PATH); if (!SetRegValue(g_lpRegKey, L"Description", L"SumatraPDF Browser Plugin") || !SetRegValue(g_lpRegKey, L"Path", szPath) || !SetRegValue(g_lpRegKey, L"Version", L"0") || !SetRegValue(g_lpRegKey, L"ProductName", L"SumatraPDF Browser Plugin")) { return E_UNEXPECTED; } ScopedMem<WCHAR> mimeType(str::Join(g_lpRegKey, L"\\MimeTypes\\application/pdf")); EnsureRegKey(mimeType); mimeType.Set(str::Join(g_lpRegKey, L"\\MimeTypes\\application/vnd.ms-xpsdocument")); EnsureRegKey(mimeType); mimeType.Set(str::Join(g_lpRegKey, L"\\MimeTypes\\application/oxps")); EnsureRegKey(mimeType); mimeType.Set(str::Join(g_lpRegKey, L"\\MimeTypes\\image/vnd.djvu")); EnsureRegKey(mimeType); mimeType.Set(str::Join(g_lpRegKey, L"\\MimeTypes\\image/x-djvu")); EnsureRegKey(mimeType); mimeType.Set(str::Join(g_lpRegKey, L"\\MimeTypes\\image/x.djvu")); EnsureRegKey(mimeType); // Work around Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=581848 which // makes Firefox up to version 3.6.* ignore all but the first plugin for a given MIME type // (per http://code.google.com/p/sumatrapdf/issues/detail?id=1254#c12 Foxit does the same) *(WCHAR *)path::GetBaseName(szPath) = '\0'; if (SHGetValue(HKEY_CURRENT_USER, L"Environment", L"MOZ_PLUGIN_PATH", NULL, NULL, NULL) == ERROR_FILE_NOT_FOUND) { WriteRegStr(HKEY_CURRENT_USER, L"Environment", L"MOZ_PLUGIN_PATH", szPath); SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 5000, NULL); } return S_OK; }
inline bool IsWirelessCard(LPCTSTR pszAdapterName) { DWORD dwType = REG_DWORD; DWORD dwCbData = sizeof(DWORD)*1; DWORD dwData = 0; TCHAR szSubKey[128] = {0, }; wsprintf(szSubKey, _T("SYSTEM\\ControlSet001\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"), pszAdapterName); // HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318} SHGetValue(HKEY_LOCAL_MACHINE, szSubKey, _T("MediaSubType"), &dwType, &dwData, &dwCbData); if(dwData == 0x01) // 01-Normal { return FALSE; } else if(dwData == 0x02) // 02-Wireless Crad { return TRUE; } return FALSE; }
BOOL CDlgSetRDPPort::LoadConfig() { BOOL bRet = FALSE; DWORD dwPortNumber = 0; DWORD dwType; DWORD dwSize; CString strTemp; dwType = REG_DWORD; dwSize = sizeof(dwPortNumber); if ( ERROR_SUCCESS == SHGetValue( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\Wds\\rdpwd\\Tds\\tcp"), _T("PortNumber"), &dwType, &dwPortNumber, &dwSize ) ) { strTemp.Format( "%d", dwPortNumber ); m_editOrgPort.SetWindowText( strTemp ); } // ... m_chkAddToFwException.SetCheck( TRUE ); return bRet; }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); if (_tcsstr(lpCmdLine, TEXT("/ui"))) { AddToSys(); } else { TCHAR buf[1024]; DWORD dwType, dwSize; LSTATUS ls = SHGetValue(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), TEXT("whip"), &dwType, buf, &dwSize); if (ERROR_FILE_NOT_FOUND == ls) { if(GetModuleFileName(NULL, exe_path_, ARRAYSIZE(exe_path_) - 1)) { TCHAR os_ver[20] = TEXT("5"); cpl::GetOSVersion(os_ver, ARRAYSIZE(os_ver)); LPCTSTR action = (os_ver[0] > '5') ? TEXT("runas") : NULL; ShellExecute(NULL, action, exe_path_, TEXT("/ui"), NULL, SW_HIDE); } } else { Report(); } } return 0; }
int fsInit(const char *dir_name) { const char *data_dir; d->fs.directory_suffix = strdup(dir_name); if (d->platform.platform & DARNIT_PLATFORM_PANDORA) { d->fs.data_dir = "."; d->fs.write_dir = "."; } else if (d->platform.platform & (DARNIT_PLATFORM_LINUX | DARNIT_PLATFORM_GCWZERO)) { #ifndef _WIN32 #ifndef PANDORA data_dir = getenv("HOME"); if ((d->fs.write_dir = malloc(strlen(data_dir) + 3 + strlen(dir_name) + strlen(".darnit/"))) == NULL) return -1; sprintf(d->fs.write_dir, "%s/.darnit", data_dir); mkdir(d->fs.write_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); sprintf(d->fs.write_dir, "%s/.darnit/%s", data_dir, dir_name); if ((d->fs.data_dir = malloc(strlen(DATA_PATH) + 2 + strlen(dir_name))) == NULL) return -1; sprintf(d->fs.data_dir, "%s/%s", DATA_PATH, dir_name); #endif #endif } else if (d->platform.platform & DARNIT_PLATFORM_WIN32) { data_dir = getenv("APPDATA"); if ((d->fs.write_dir = malloc(strlen(data_dir) + 2 + strlen(dir_name))) == NULL) return -1; sprintf(d->fs.write_dir, "%s/%s", data_dir, dir_name); /* Ugh... WinAPI... */ #ifdef _WIN32 char tmp[256], val[256]; int sz=256; sprintf(tmp, "SOFTWARE\\libdarnit\\%s", dir_name); if (SHGetValue(HKEY_LOCAL_MACHINE, tmp, "path", NULL, val, (LPDWORD) &sz) != ERROR_SUCCESS) d->fs.data_dir = "."; else { if ((d->fs.data_dir = malloc(strlen(val) + 1)) == NULL) d->fs.data_dir = "."; else sprintf(d->fs.data_dir, "%s", val); } #else d->fs.data_dir = "."; #endif } else { /* TODO: Add more platforms */ d->fs.data_dir = (char *) "."; d->fs.write_dir = (char *) "."; } #ifdef _WIN32 CreateDirectory(d->fs.write_dir, NULL); #else mkdir(d->fs.write_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); #endif d->fs.mount = NULL; d->fs.temp_counter = 0; return 0; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 命令处理 VOID CMainWnd::OnCommand(WPARAM wParam, LPARAM lParam) { PTSTR p; DWORD dwSize; CChildWnd *pWnd; TCHAR tzTemp[512]; TCHAR tzPath[512]; if ((LOWORD(wParam) >= IDM_View_Default) && (LOWORD(wParam) < IDM_View_Default + 50)) { // 改变语言 if (IsMenuChecked(LOWORD(wParam)) == FALSE) { OnViewLanguage(LOWORD(wParam)); } return; } else if ((LOWORD(wParam) >= IDM_File_Recent) && (LOWORD(wParam) < IDM_File_Recent + 10)) { // 打开新近文件 GetMenuString(m_hMenu, LOWORD(wParam), tzTemp, _NumOf(tzTemp), MF_BYCOMMAND); OnFileOpen(tzTemp + 4); return; } switch (LOWORD(wParam)) { case IDM_File_Open: OnFileOpen((PTSTR) lParam); break; case IDM_File_Exit: PostMessage(m_hWnd, WM_CLOSE, 0, 0); break; case IDM_View_Toolbar: case IDM_View_StatusBar: case IDM_View_AlwaysOnTop: case IDM_View_MinToTray: case IDM_View_ShowSplash: case IDM_View_ShowOpen: case IDM_View_PlayOnOpen: // 查看选项 OnViewMenu(LOWORD(wParam), FALSE); break; case IDM_View_AssociateFile: GetModuleFileName(NULL, tzPath, MAX_PATH); wsprintf(tzTemp, TEXT("\"%s\" \"%%1\""), tzPath); dwSize = _NumOf(tzPath); SHGetValue(HKEY_CLASSES_ROOT, STR_AppName TEXT("\\shell\\open\\command"), NULL, NULL, tzPath, &dwSize); if (lstrcmpi(tzTemp, tzPath) == 0) { SHDeleteKey(HKEY_CLASSES_ROOT, STR_AppName); for (p = STR_ExtList; *p; p += lstrlen(p) + 1) { SHDeleteKey(HKEY_CLASSES_ROOT, p); } } else { SHSetValue(HKEY_CLASSES_ROOT, STR_AppName TEXT("\\shell\\open\\command"), NULL, REG_SZ, tzTemp, _StrSize(tzTemp)); GetModuleFileName(NULL, tzPath, MAX_PATH); wsprintf(tzTemp, TEXT("\"%s\",1"), tzPath); SHSetValue(HKEY_CLASSES_ROOT, STR_AppName TEXT("\\DefaultIcon"), NULL, REG_SZ, tzTemp, _StrSize(tzTemp)); for (p = STR_ExtList; *p; p += lstrlen(p) + 1) { SHSetValue(HKEY_CLASSES_ROOT, p, NULL, REG_SZ, STR_AppName, sizeof(STR_AppName)); } } break; case IDM_Window_Cascade: SendMessage(CClientWnd::m_hWnd, WM_MDICASCADE, 0, 0); return; case IDM_Window_TitleHorz: SendMessage(CClientWnd::m_hWnd, WM_MDITILE, MDITILE_HORIZONTAL, 0); break; case IDM_Window_TitleVert: SendMessage(CClientWnd::m_hWnd, WM_MDITILE, MDITILE_VERTICAL, 0); break; case IDM_Window_ArrangeIcons: SendMessage(CClientWnd::m_hWnd, WM_MDIICONARRANGE, 0, 0); break; case IDM_Window_CloseAll: CClientWnd::CloseAll(); break; case IDM_Help_Content: // 查看帮助内容 GetModuleFileName(NULL, tzTemp, MAX_PATH); lstrcpy(_StrEnd(tzTemp) - _LenOf(EXT_Chm), EXT_Chm); if (ShellExecute(NULL, NULL, tzTemp, NULL, NULL, SW_SHOW) <= (HINSTANCE) 32) { ErrorBox(ERR_HelpErr); } break; case IDM_Help_Desktop: case IDM_Help_StartMenu: case IDM_Help_ProgramMenu: case IDM_Help_QuickLaunch: case IDM_Help_VisualStudio: // 创建或删除快捷方式 OnHelpShortcut(LOWORD(wParam)); break; case IDM_Help_About: // 显示关于对话框 CAboutDlg::Show(m_hWnd); break; case IDC_TrayIcon: // 系统托盘消息 if ((lParam == WM_LBUTTONUP) || (lParam == WM_RBUTTONUP)) { OnTrayIcon(FALSE); } break; default: pWnd = CClientWnd::GetChildWnd(); _ExIf(pWnd, pWnd->OnCommand(wParam, lParam)); } }
// // initialization // STDMETHODIMP CSDShellExt::Initialize (LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; HDROP hDrop; // // Look for CF_HDROP data in the data object. If there // is no such data, return an error back to Explorer. // if (FAILED(pDataObj->GetData(&fmt, &stg))) { return E_INVALIDARG; } // // check if extension is enabled // DWORD bufferSize = 4; DWORD keyType = REG_DWORD; SHGetValue(HKEY_CURRENT_USER, SecureDeleteKey, ShellNormalEnabled, &keyType, &normalEnabled, &bufferSize); SHGetValue(HKEY_CURRENT_USER, SecureDeleteKey, ShellMoveEnabled, &keyType, &moveEnabled, &bufferSize); SHGetValue(HKEY_CURRENT_USER, SecureDeleteKey, ShellRecycleEnabled, &keyType, &recycleEnabled, &bufferSize); if(!normalEnabled && !moveEnabled && !recycleEnabled) { // none of the features enabled return E_INVALIDARG; } // // reset data header // dataHeader.operationType = 0; dataHeader.objectCount = 0; // // get drop folder if drag-n-drop operation // if(pidlFolder != NULL && SHGetPathFromIDList(pidlFolder, dataHeader.data1)) { dataHeader.operationType = MOVE_OPERATION; } // // Get a pointer to the actual data. // hDrop = (HDROP)GlobalLock(stg.hGlobal); // // Make sure it worked. // if (hDrop == NULL) { return E_INVALIDARG; } // // get the files // unsigned int fileNumber = DragQueryFile (hDrop, 0xFFFFFFFF, NULL, 0); HRESULT hr = S_OK; if (fileNumber == 0) { GlobalUnlock (stg.hGlobal); ReleaseStgMedium (&stg); return E_INVALIDARG; } // // get the file names // wchar_t buffer[MAX_PATH]; ClearFileList(); for(unsigned int i = 0;i < fileNumber;i++) { if(DragQueryFile(hDrop, i, buffer, MAX_PATH) == 0) { // // error, abort // hr = E_INVALIDARG; break; } // // allocate string // int length = wcslen(buffer); wchar_t *name = new wchar_t[length + 1]; wcscpy(name, buffer); // // insert into the list // fileList.insert(&name); } GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return hr; }
BOOL ReadRegDWord(HKEY hkey, LPCTSTR pszSubKey, LPCTSTR pszValue, DWORD &dw) { DWORD dwSize = sizeof(DWORD); DWORD dwType = REG_DWORD; return ERROR_SUCCESS == SHGetValue( hkey, pszSubKey, pszValue, &dwType, &dw, &dwSize ); }
HRESULT PAGE(PTSTR ptzCmd) { // Parse size UINT uMin = 0; UINT uMax = 0; PTSTR p = UStrChr(ptzCmd, ' '); if (p) { *p++ = 0; uMin = UStrToInt(p); p = UStrChr(p, ' '); if (p) { *p++ = 0; uMax = UStrToInt(p); } } if (uMax<uMin) { uMax=uMin; } // Get DOS device name for page file TCHAR tzDrive[16]; TCHAR tzDos[MAX_PATH]; TCHAR tzFile[MAX_PATH]; tzDrive[0] = ptzCmd[0]; tzDrive[1] = ptzCmd[1]; tzDrive[2] = 0; UStrCopy(tzFile, ptzCmd + 2); QueryDosDevice(tzDrive, tzDos, MAX_PATH); UStrCat(tzDos, tzFile); WCHAR wzPath[MAX_PATH]; UStrToWStr(wzPath, tzDos, MAX_PATH); UNICODE_STRING sPath; sPath.Length = UWStrLen(wzPath) * sizeof(WCHAR); sPath.MaximumLength = sPath.Length + sizeof(WCHAR); sPath.Buffer = wzPath; // Fill size param ULARGE_INTEGER ulMax, ulMin; ulMin.QuadPart = uMin * 1024 * 1024; ulMax.QuadPart = uMax * 1024 * 1024; // Get function address typedef NTSTATUS (NTAPI* PNtCreatePagingFile)(PUNICODE_STRING sPath, PULARGE_INTEGER puInitSize, PULARGE_INTEGER puMaxSize, ULONG uPriority); PNtCreatePagingFile NtCreatePagingFile = (PNtCreatePagingFile) GetProcAddress(GetModuleHandle(TEXT("NTDLL")), "NtCreatePagingFile"); if (!NtCreatePagingFile) { return E_FAIL; } // Create page file Priv(SE_CREATE_PAGEFILE_NAME); HRESULT hResult = NtCreatePagingFile(&sPath, &ulMin, &ulMax, 0); if (hResult == S_OK) { // Log to Windows Registry TCHAR tzStr[MAX_PATH]; DWORD i = sizeof(tzStr); if (SHGetValue(HKEY_LOCAL_MACHINE, REG_MemMgr, REG_PageFile, NULL, tzStr, &i) != S_OK) { i = 0; } else { i = (i / sizeof(TCHAR)) - 1; } i += UStrPrint(tzStr + i, TEXT("%s %d %d"), ptzCmd, uMin, uMax); tzStr[++i] = 0; SHSetValue(HKEY_LOCAL_MACHINE, REG_MemMgr, REG_PageFile, REG_MULTI_SZ, tzStr, i * sizeof(TCHAR)); } return hResult; }
bool GetRegistryString(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, WCHAR* data, DWORD dataSize) { DWORD type; return (SHGetValue(rootKey, subKey, value, &type, data, &dataSize) == ERROR_SUCCESS && type == REG_SZ); }
BOOL RegValueExists( HKEY hRoot, LPCTSTR lpSubKey, LPCTSTR lpValueName ) { DWORD dwType; DWORD dwSize; return SHGetValue(hRoot, lpSubKey, lpValueName, &dwType, NULL, &dwSize)==ERROR_SUCCESS; }