How to gain full read/write access to user's AppData folder using a "C" program?

Thad T 26 Reputation points
2023-06-18T19:02:24.4066667+00:00

Question: I've tried several times to access the user's AppData area programmatically using MSVC 2019 "C" program, but I am unable to gain full read/write access to it. Though it's easy to manually put a file into the area, using a program doesn't seem to work. I am wondering why these areas exist if we can't use them. Can someone provide a solid "C" programming example that demonstrates how to gain access to these areas and place files into them? Also, what steps do I need to follow to have full read/write access into these areas, similar to what other big name programs can do? Could you please provide detailed steps, "C" code snippets, and any relevant documentation to show me how I can full access to the user's appdata areas. Thad.

Windows development | Windows API - Win32
Windows for business | Windows Client for IT Pros | Devices and deployment | Configure application groups
Developer technologies | C++
Developer technologies | Visual Studio | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2023-06-18T19:51:13.5+00:00

    This simple test creates a "Test" folder in my user appdata folder

    (C:\Users\Username\AppData\Roaming on my PC (Windows 10 22H2) ) :

    					WCHAR wszPath[MAX_PATH] = L"";					
    					if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, wszPath)))
    					{
    						PathAppend(wszPath, L"Test");
    						if (!PathFileExists(wszPath))
    						{
    							BOOL bRet = CreateDirectory(wszPath, NULL);
    						}
    					}
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.