Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a program which use ini file. That file should be in C:/Windows - so I use GetPrivateProfileString api function with last parameter set to 'myfile.ini' (without full path because: "The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory. "

But I have a problem, because function sometimes reads from main Window, sometimes from VirtualStore.. I think it depends on how I run application (as admin or not) - but I'm not sure.

I want to have this ini file in Windows dir and makes it works every time (on Windows Vista and 7) - is it possible? Or I have to save that ini file somewhere else ?

Thanks for your help,
Posted

1 solution

Consider using the registry rather than using an INI file. Writing files to Windows system directories should be avoided (and requires Administrator or Power User privileges).
 
Share this answer
 
Comments
mnd017 11-Jan-12 6:33am    
Thanks, but I really need to use ini files. Is there any api function which determine whether program was launched as administrator?
Jochen Arndt 11-Jan-12 6:41am    
There should be a way to determine this, but I don't know it. Another option would be to store the INI file in an app specific subdirectory of the common application data folder (use ::SHGetFolderPath with CSIDL_COMMON_APPDATA to determine the path).
Jochen Arndt 11-Jan-12 6:56am    
I just remembered that I have done such determination:
- Get a SID from AllocateAndInitializeSid() with SECURITY_BUILTIN_DOMAIN_RID and DOMAIN_ALIAS_RID_ADMINS
- Use CheckTokenMembership() with handle NULL to check wether the current threads impersonation token matches the SID.
mnd017 11-Jan-12 7:52am    
Thanks, w will try that in a moment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900