[MFC]几个用户目录的获取

(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源)

 

window7中,进入命令行cmd模式,输入set到多个系统目录定义:

例如:

Win7:

APPDATA=c:\users\xxx\AppData\Roaming

LOCALAPPDATA=c:\users\xxx\AppData\Local

USERPROFILE=c:\users\xxx

ALLUSERPROFILE=c:\ProgramData

HOMEPATH=c:\users\xxx

TEMP= c:\users\xxx\AppData\Local \Temp

TMP= c:\users\xxx\AppData\Local \Temp

 

Xp:

APPDATA=c:\ Documents and Setting\xxx\Application Data

LOCALAPPDATA

USERPROFILE= c:\ Documents and Setting \xxx

ALLUSERPROFILE=c:\Documents and Setting\Allusers

HOMEPATH=c: \Documents and Setting\xxx

TEMP=c:\DOCUME~1\xxx\LOCALS~1\Temp

TMP= c:\DOCUME~1\xxx\LOCALS~1\Temp

 

说明:

APPDATA-软件使用时用户的配置信息通常写到此

LOCALAPPDATA-临时目录通常创建到这里

ALLUSERPROFILE-通常软件的鉴权信息写入到

HOMEPATH-用户目录

TEMP/TMP- 临时文件夹,可以随时被清理

 

获取LOCALAPPDATA/ APPDATA/USERPROFILE /ALLUSERPROFILE:

CString sPath;

SHGetFolderPath( NULL, CSIDL_ LOCALAPPDATA/, NULL, 0, sPath.GetBuffer(MAX_PATH) );

sPath.ReleaseBuffer();

 

类似还支持: CSIDL_LOCALAPPDATA /CSIDL_APPDATA/CSIDL_PROFILE(参考shlobj.h)

 

获取临时目录TEMP/TMP:

// 获取临时文件夹

CString sTempPath;

::GetTempPath(MAX_PATH, sTempPath.GetBuffer(MAX_PATH));

sTempPath.ReleaseBuffer();

 

CString sTempFile;

// 获取临时文件: 输入文件名前缀,自动获得一个不重复的文件名

::GetTempFileName(sTempPath, _T(MyPre_), 0, sTempFile.GetBuffer(MAX_PATH));

sTempFile.ReleaseBuffer();

 

(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源)

 

 

你可能感兴趣的:(用户目录)