How to get a full path to Temp and Application Data



  • In view of the system file Temp Total WINDOWS\ and Application Data (sighs)%APPDATA%)



  • %APPDATA% e.g. function SHGetFolderPath or getenv from the standard library, %TEMP% for the current user . - GetTempPath or the same getenv♪ Here's to get file ♪ %TEMP% I have to use the function. ExpandEnvironmentStringsForUser:

    #include <iostream>
    

    #include <windows.h>
    #include <Shlobj.h>
    #include <Userenv.h>

    int main()
    {
    TCHAR szPath[MAX_PATH];
    char* path;

    if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) {
        std::cout &lt;&lt; "%APPDATA% (SHGetFolderPath) = " &lt;&lt; szPath &lt;&lt; std::endl;
    }
    
    path = getenv("APPDATA");
    if (path != NULL) {
        std::cout &lt;&lt; "%APPDATA% (getenv) = " &lt;&lt; path &lt;&lt; std::endl;
    }
    
    if (GetTempPath(MAX_PATH, szPath)) {
        std::cout &lt;&lt; "User's %TEMP% (GetTempPath) = " &lt;&lt; szPath &lt;&lt; std::endl;
    }
    
    path = getenv("TEMP");
    if (path != NULL) {
        std::cout &lt;&lt; "User's %TEMP% (getenv) = " &lt;&lt; path &lt;&lt; std::endl;
    }
    
    if (ExpandEnvironmentStringsForUser(NULL, "%TEMP%", szPath, MAX_PATH)) {
        std::cout &lt;&lt; "System's %TEMP% = " &lt;&lt; szPath &lt;&lt; std::endl;
    }
    
    return 0;
    

    }

    For use ExpandEnvironmentStringsForUser We're gonna need to get attached. Userenv.dll




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2