1. 程式人生 > >C++獲取系統環境變數

C++獲取系統環境變數

	TCHAR szOutBuf[MAX_PATH] = {0};
	GetEnvironmentVariable( _T("ProgramFiles"), szOutBuf, MAX_PATH - 1 );

	TCHAR szOutBuf2[MAX_PATH] = {0};
	GetEnvironmentVariable( _T("ProgramFiles(x86)"), szOutBuf2, MAX_PATH - 1 );

	TCHAR szSourcePath[MAX_PATH] = _T("%ProgramFiles%\\Tencent\\QQBrowser");
	TCHAR szDestPath[MAX_PATH] = {0};
	ExpandEnvironmentStrings( szSourcePath, szDestPath, MAX_PATH - 1 );

	TCHAR szSourcePath2[MAX_PATH] = _T("%ProgramFiles(x86)%\\Tencent\\QQBrowser");
	TCHAR szDestPath2[MAX_PATH] = {0};
	ExpandEnvironmentStrings( szSourcePath2, szDestPath2, MAX_PATH - 1 );

	TCHAR szSourcePath3[MAX_PATH] = _T("%ProgramW6432%\\Tencent\\QQBrowser");
	TCHAR szDestPath3[MAX_PATH] = {0};
	ExpandEnvironmentStrings( szSourcePath3, szDestPath3, MAX_PATH - 1 );