I know there are plenty of similar questions out there like this one how to get %AppData% path
But mine is different:
1.I have two account:
Admin- Administrator account
Test- Non-Administrator account
2.Run my project using VS2013 as a Administrator cause the project requires to have elevated permissions. Then using the following code snippet to get the appdata path:
TCHAR szPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath)))
{
//....
}
But the actual value of szPath
is C:\Users\Admin\AppData\Roaming
, not C:\Users\Test\AppData\Roaming
that I wanted.
Anyone knows how to do that? Thanks in advance.
The root cause of your problem is running VS as "Admin" account. As long as you keep doing it, %AppData% will point to that account's appdata folder. No suprises.
So, you have to change your approach. Some options:
and so on.. there are many options, everything depends on what you are willing to change in your methodology..
regarding 4th one: try this thing - find a shortcut to 'Commandline' (cmd.exe) in your start menu. Right-click on it. You should see option "Run as administrator" (NOT "Run as other user..") Use it. Once console opens, write: echo %APPDATA%
and check what it is. It should point to YOUR appdata, yet on the window title bar you should see Administrator:CommandPrompt
warning info. Now write start cmd.exe
. Another admin-console should pop up prooving that elevation propagates to child processes. Check APPDATA in the new console, it should still be yours. That was just a test.
If console worked and propagated elevation and env vars, then you should also be able to pick "Run as administrator" on the VisualStudio icon directly. And that's all.