Stupid question 659!

Everything else that doesn't fall into one of the other PB categories.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Stupid question 659!

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Windows XP SP3 wrote:C:\Dokumente und Einstellungen\All Users.WINDOWS\Anwendungsdaten
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks Fluid.

Would I be correct in saying that that folder would be accessible to all users regardless of account type?
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
Last edited by Sparkie on Sat Apr 11, 2009 1:29 pm, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Windows 2000 also reports "C:\Documents and Settings\All Users\Application Data"
quidquid Latine dictum sit altum videtur
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

For the fun of it: NT4 and Windows 95 return an empty string ;)
quidquid Latine dictum sit altum videtur
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ahh, I see. :)
I may look like a mule, but I'm not a complete ass.
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post 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 :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.

:)
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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?
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post 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.
Post Reply