您可以使用 SHGetKnownFolderPath 获取App Local的完整路径:
SHGetKnownFolderPath
... #include <KnownFolders.h> #include <ShlObj.h> ... SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_SIMPLE_IDLIST, NULL, &path); // NULL for current user ...
要获取用户名:
char username[MAX_PATH]; DWORD size = MAX_PATH; GetUserName(username,&size);
要获取appname(不带“.exe”的可执行文件名):
char appname[MAX_PATH]; GetModuleFileName(NULL, appname,MAX_PATH); //get the string: "PATH\\appname.exe" char szExe[MAX_PATH] = {0}; char *pbuf = NULL; //Remove prefix char* szLine = strtok_s(appname, "\\", &pbuf); while (NULL != szLine) { strcpy_s(szExe, szLine); szLine = strtok_s(NULL, "\\", &pbuf); } //Remove suffix strncpy_s(appname, szExe, strlen(szExe) - strlen(".exe"));