Page 1 of 2

Stupid question 659!

Posted: Sat Apr 11, 2009 1:11 pm
by srod
Hi,

this is perhaps a daft question; well, advice seeking really.

Wishing to avoid using the registry; I wish to place a 'global' preferences file accessible to all users on the computer regardless of whether they are running as an admin or a standard user etc.

On Vista, the folder returned by #CSIDL_COMMON_APPDATA (with the code below) is a likely looking candidate. On my Vista machine this returns "C:\ProgramData" and seems to be accessible to all users regardless.

Has anyone a better suggestion?

I'll use the registry if I have to, but I generally like to steer away from that.

The code I used to retrieve the folder in question is :

Code: Select all

Procedure.s GetSpecialFolder(SpecialFolder) 
  Define ListPtr.l, SpecialFolderPath.s 
  SpecialFolderPath = Space(#MAX_PATH) 
  If SHGetSpecialFolderLocation_(0, SpecialFolder, @ListPtr) = #NOERROR 
    SHGetPathFromIDList_(ListPtr, @SpecialFolderPath) 
  EndIf 
  ProcedureReturn Trim(SpecialFolderPath) 
EndProcedure 
If someone could report what XP or Win 2000 reports for #CSIDL_COMMON_APPDATA then I would be grateful.

Thanks.

Posted: Sat Apr 11, 2009 1:24 pm
by Fluid Byte
Windows XP SP3 wrote:C:\Dokumente und Einstellungen\All Users.WINDOWS\Anwendungsdaten

Posted: Sat Apr 11, 2009 1:26 pm
by srod
Thanks Fluid.

Would I be correct in saying that that folder would be accessible to all users regardless of account type?

Posted: Sat Apr 11, 2009 1:28 pm
by Sparkie
On my XP Home SP3, #CSIDL_COMMON_APPDATA = C:\Documents and Settings\All Users\Application Data

Same path whether I'm logged on as Admin or Guest

Posted: Sat Apr 11, 2009 1:29 pm
by srod
That is what I was expecting on XP. I am hoping Fluid's is just a German equivalent!

Unfortunately, having recently restored my hard-drive from a rather nasty virus I haven't as yet gotten around to reinstalling the various VM's I was using. :)

Thanks.

Posted: Sat Apr 11, 2009 2:09 pm
by freak
Windows 2000 also reports "C:\Documents and Settings\All Users\Application Data"

Posted: Sat Apr 11, 2009 2:11 pm
by srod
That'll do the job then. Any OS earlier than Win2000 can go take a run and jump into the nearest cess pit! :)

Thanks.

Posted: Sat Apr 11, 2009 2:12 pm
by freak
For the fun of it: NT4 and Windows 95 return an empty string ;)

Posted: Sat Apr 11, 2009 2:14 pm
by srod
freak wrote:For the fun of it: NT4 and Windows 95 return an empty string ;)
hehe, now why am I not surprised! :)

I don't support Win 95/98 or that ME rubbish... bit surprised by NT though I guess.

Posted: Sat Apr 11, 2009 2:28 pm
by Fluid Byte
srod wrote:That is what I was expecting on XP. I am hoping Fluid's is just a German equivalent!
Nah, it's just my system which is a mess. :P

I had to reinstall the system but couldn't delete the old user. But I wanted to keep my old login name so Windows had to rename the folders for the new/old profile: http://www.codedreality.de/tl_files/tem ... ttings.png

Posted: Sat Apr 11, 2009 6:25 pm
by srod
Ahh, I see. :)

Posted: Sat Apr 11, 2009 10:31 pm
by mback2k
I am also using a subfolder inside CSIDL_COMMON_APPDATA for the global settings of my projects. You need to be careful about Vista's UAC. If you use an installer with your project and let it start the application after the installation and the process creates your subfolder and setting files at this time, those files would be owned by the Administrator and not the current user. If your application does not require administrative privileges on Vista you would never be able to change the settings again.

Solution 1: Let the installer run the application under user privileges (NSIS plugin) so that the user who installed the application can write to the files and all others are able to read from them.

Solution 2: Make the application require adminstrative privileges so that Administrators can write to the files and all others are able to read from them.

Solution 3: Remove any security objects from the files after initial creation so that everyone can do everything with the files.

Basically you must keep in mind that under Vista only the user who created the folder and files can write to them later on. You can avoid this by removing the security objects from the files.

I hope that information helps :)

Posted: Sun Apr 12, 2009 11:11 am
by srod
Thanks for the info.

I see now that my tests were not detailed enough. I shall run some more now. All I need do is create a single file within this folder (doesn't even need to be within a subfolder) so that all users can read/write from/to it.

:)

Posted: Mon Apr 13, 2009 5:12 pm
by SFSxOI
Can't you just use the %SYSTEM% path so it goes into what ever the windows folder is called on all windows systems? Doesn't the %SYSTEM% enviroment spec hold the name of the windows folder used? If so then the file would go to C:\Windows or C:\MyWindows or C:\WinNT no matter what the windows folder was called it would still be in the correct place on all systems and accessable by admin and user alike?

Posted: Mon Apr 13, 2009 5:24 pm
by mback2k
SFSxOI wrote:Can't you just use the %SYSTEM% path so it goes into what ever the windows folder is called on all windows systems? Doesn't the %SYSTEM% enviroment spec hold the name of the windows folder used? If so then the file would go to C:\Windows or C:\MyWindows or C:\WinNT no matter what the windows folder was called it would still be in the correct place on all systems and accessable by admin and user alike?
Ugh, no! Write access to the %SYSTEM% path is not granted to everyone and an application should never write to such a location.