Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - How to get the user folder?

Tags:

c++

directory

vcl

I'm having a little problem with my program...

I have to create a file with the application data, but I don't know how to access the %USER% or %APPDATA% directories...

I've tried to use the application folder, but if I install the application in D:\Program Files\(Organization)\(APPName) I cannot write new files in this directory, I can just read or modify if I don't have admin privileges...

So, the question is: How to access the %USER% folder or Get ADMIN privileges with the application... PS.: I'm using VCL in C++ Builder

like image 338
mauroaraujo Avatar asked Jan 29 '14 10:01

mauroaraujo


People also ask

How do I find the users folder?

You can open it from the Start menu (Windows System → File Explorer). Or, press the keyboard shortcut Windows key + E (hold down the Windows key and press E). Click in the location bar. Type %USERPROFILE% and press Enter .

What is Users folder in C drive?

Users folder coming with C drive is set by default when installing the Windows operating system. The folder contains multiple sub-folders which are used to keep some frequently used data, such as users profile, contacts, favorites, downloads, music, documents, videos, games, etc.

Where is the Users folder in Windows 10?

Right-click an empty area on the navigation panel in File Explorer. From the context menu, select the 'Show all folders' and your user profile will be added as a location in the navigation bar. What is this? Each time you open File Explorer, you will be able to quickly access it from the navigation panel.

How do I find the users directory in Linux?

The root (administrative) user is the only user who has its home directory in a different location by default. The path of the root user is '/root/', where it has control under all the directories and files.


1 Answers

Assuming this is a pure Windows question, you should use SHGetSpecialFolderPath.

  • Pass CSIDL_PROFILE to get the equivalent of %USERPROFILE%.
  • Pass CSIDL_APPDATA to get the equivalent of %APPDATA%.

Note that the documentations for the CSIDL based functions are a little scary in that they talk about function not being supported or deprecated. Instead they urge you to use SHGetKnownFolderPath. That's fine if your program never needs to run on XP. If that's the case, go ahead and use SHGetKnownFolderPath. Otherwise, use the CSIDL based options.

like image 188
David Heffernan Avatar answered Sep 27 '22 23:09

David Heffernan