当前位置: 首页>>代码示例>>C++>>正文


C++ ExpandEnvironmentStrings函数代码示例

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


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


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