#include <windows.h>
#include <stdio.h>
#define ENV_VAR_STRING_COUNT (sizeof(envVarStrings)/sizeof(TCHAR*))
#define INFO_BUFFER_SIZE 32768

int main(int argc, char* argv[])
{
	TCHAR infoBuf[INFO_BUFFER_SIZE];
	DWORD bufCharCount = INFO_BUFFER_SIZE;

	bufCharCount = ExpandEnvironmentStrings( "%USERPROFILE%", infoBuf, INFO_BUFFER_SIZE );
	printf("USER_DIRECTORY:%s", infoBuf );
	printf("\n");

	return 0;
}

 

이거 말고도 다른 방법도 있고
시스템 환경 변수를 얻어내는 방법도 있다.
컴퓨터 이름 얻을때 : GetComputerName
사용자 이름 얻을때 : GetUserName
시스템 디렉토리 얻을때 : GetSystemDirectory
윈도우 디렉토리 얻을때 : GetWindowsDirectory
PATH나 OS 디렉토리 같은거 얻어낼때(환경변수에 있는거만) : ExpandEnvironmentStrings

Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Unicode: Implemented as Unicode and ANSI versions. Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.


기타 시스템 관련 함수들 리스트

ExpandEnvironmentStrings 
GetComputerName 
GetCurrentHwProfile 
GetKeyboardType 
GetSysColor 
GetSystemDirectory 
GetSystemInfo 
GetSystemMetrics 
GetUserName 
GetVersionEx 
GetWindowsDirectory 
IsProcessorFeaturePresent 
SetComputerName 
SetSysColors 
SystemParametersInfo

[출처] [VC++] 윈도우에 사용자 디렉토리 알아내기... |작성자 복운여왕

Posted by yyht
,