Windows equivalent for system configuration directory

I am developing an application in the Ruby CLI, and I would like to allow setting on Unix via standard cascade configuration file /etc/appnamerc, ~/.appnamerc. However, the application is also intended to run in a Windows environment, and I'm not sure where you can place a file of the type /etc/appnamerc(it C:\windows\system32\etc\driversdoesn't seem like it will be the right place). In addition, any scheme that I decide to search for a system configuration file must also consider different versions of Windows, i.e. C:\Usersand C:\Documents and Settings. As for the user-specific configuration, I'm also not sure where to look for the application for the configuration file for a specific user, and what is the standard naming convention for something like that.

+3
source share
3 answers

What you are looking for is the SHGetKnownFolderPath function (or - on older versions of Windows - the SHGetFolderPath function ).

While Windows has conventions that these paths and where they are located are completely dependent on version, configuration, and other factors, so hard-coded folder names are a bad idea. However, the above was the function of getting these "special" folder locations from the very beginning.

The main argument of these functions is either KNOWNFOLDERID , or CSIDL , which indicates which folder you want.

"", : Windows. , , . .

, , :

  • FOLDERID_ProgramData/CSIDL_COMMON_APPDATA: , /etc/foorc. . , (, , /etc). .
  • FOLDERID_RoamingAppData/CSIDL_APPDATA: . , , , , . , ~/.foorc. , .
  • FOLDERID_LocalAppData/CSIDL_LOCAL_APPDATA: . , , , , . , Thunderbird , IMAP - , GiB .

, .foorc . Windows UNIX, , , ( ). , , Windows. , "" .

Ruby Win32API. ( ); , , .

. ALLUSERSPROFILE, APPDATA LOCALAPPDATA FolderID.

+1

Windows , , API SHGetSpecialFolderPath. .

, :

char szBuffer[1024];

// get the common application data folder
::SHGetSpecialFolderPath(0, szBuffer, CSIDL_COMMON_APPDATA, false);
+2

shGetSpecialFolderLocation. β†’ CSIDL_COMMON_APPDATA, CSIDL_LOCAL_APPDATA, CSIDL_COMMON_DOCUMENTS CSIDL_PERSONAL

- . : http://www.icetips.com/blog/index.php/2008/10/31/title

+1

Source: https://habr.com/ru/post/1734959/


All Articles