• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ExpandEnvironmentStrings函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ExpandEnvironmentStrings函数的典型用法代码示例。如果您正苦于以下问题:C++ ExpandEnvironmentStrings函数的具体用法?C++ ExpandEnvironmentStrings怎么用?C++ ExpandEnvironmentStrings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ExpandEnvironmentStrings函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: while

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;
}
开发者ID:quachdnguyen,项目名称:locate-src,代码行数:49,代码来源:Shell.cpp


示例2: ucmAppcompatElevation

/*
* 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;
}
开发者ID:1872892142,项目名称:UACME,代码行数:57,代码来源:gootkit.c


示例3: get_string

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;
}
开发者ID:kirillkovalenko,项目名称:nssm,代码行数:49,代码来源:registry.cpp


示例4: DllMain

/*
* 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;
}
开发者ID:601040605,项目名称:UACME,代码行数:57,代码来源:dllmain.c


示例5: RegisterSmartCard

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 );
}
开发者ID:CardContact,项目名称:OpenSC,代码行数:15,代码来源:customactions.cpp


示例6: strcat

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;
}
开发者ID:hkaiser,项目名称:TRiAS,代码行数:36,代码来源:Esnecil.cpp


示例7: PerformCommonGitPathCleanup

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");
}
开发者ID:HsingChin,项目名称:TortoiseGit,代码行数:24,代码来源:SetMainPage.cpp


示例8: ExpandEnvStr

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;
}
开发者ID:BigVal71,项目名称:ConEmu,代码行数:24,代码来源:WObjects.cpp


示例9: GetPropertyStore

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;
}
开发者ID:gleefeng,项目名称:exifEditTest,代码行数:15,代码来源:PropertyEdit.cpp


示例10: ReadIni

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));
}
开发者ID:Eun,项目名称:MoveToDesktop,代码行数:15,代码来源:hook.cpp


示例11: auptchExpanded

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);
		}
	}
}
开发者ID:hackshields,项目名称:antivirus,代码行数:15,代码来源:UncontrolledFiles.cpp


示例12: ExpandEnvironmentStrings

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
}
开发者ID:JxbSir,项目名称:JxbIMClient,代码行数:15,代码来源:util_mosq.c


示例13: GetEventMessageFileName

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);
}
开发者ID:trieck,项目名称:source,代码行数:48,代码来源:EventAge.c


示例14: pathToAbsolute

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;
}
开发者ID:0xmono,项目名称:miranda-ng,代码行数:16,代码来源:general.cpp


示例15: ParseSubMenuPathList

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;
}
开发者ID:wowngasb,项目名称:kl_tool,代码行数:16,代码来源:taskbar.cpp


示例16: lilv_expand

/** 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;
}
开发者ID:discokid,项目名称:Carla,代码行数:48,代码来源:util.c


示例17: uninstall

// 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;
}
开发者ID:A-Massarella,项目名称:Botnet,代码行数:48,代码来源:misc.cpp


示例18: terminateIe

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;
}
开发者ID:Escobita,项目名称:selenium,代码行数:47,代码来源:webdriver.cpp


示例19: OnBnClickedAdvanced

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);
}
开发者ID:nicklepede,项目名称:onesnap,代码行数:17,代码来源:SnapperOptions.cpp


示例20: GetRegistryInstallPath

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;
}
开发者ID:garinh,项目名称:cs,代码行数:46,代码来源:instpath.cpp



注:本文中的ExpandEnvironmentStrings函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ExpandEnvironmentStringsW函数代码示例发布时间:2022-05-30
下一篇:
C++ Exp函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap