[Qt-interest] Windows 7 and VirtualStore woes [MY SOLUTION]
Oliver Demetz
forenbeitraege at oliverdemetz.de
Tue Sep 22 21:11:56 CEST 2009
Well,
after this topic has been discussed extensively, I want to post my
working solution here, just in case that someone else is confronted with
the same problem:
The valid location to store my application data is as posted by Pascal
the CSIDL_COMMON_APPDATA.
On WindowsXP this points to c:\Documents and Settings\All
Users\Application Data and on Vista and Windows 7 it resolves to
C:\ProgramData.
I am retrieving the actual location in my NSIS setup via the commands
SetShellVarContext all
Then in the variable $APPDATA, the desired path is available.
Ok. Now my setup (that runs with administrative privileges) will create
subdirs in $APPDATA for my app and - IMPORTANT - change the permissions
on those subdirs, eg with NSIS
AccessControl::GrantOnFile "$APPDATA\My App" "(BU)" "FullAccess"
Ok. Then I have to write the complete path of the created path to the
registry, to HKLM - and not to HKCU, since every user shall use tha same
storage location.
Note that it is not a problem to create a QSettings object that accesses
the HKLM, if you just try to read from it, neither Vista nor Windows 7
will complain such an access or redirected it to the VirstualStore.
So if you write the path eg. to HKLM\Software\MyApp\StoragePath,
then a QSettings object
QSettings s("HKLM\\Software\\MyApp",QSettings::NativeFormat);
s.value("StorageLoaction");
will get the desired location, also if the app is run in normal user mode.
Ok. That was it, since we changed the rights, every user can read, write
and create files in this location. And all users will access the same data.
Hope this can help somebody...
Regards,
Oliver
Pascal Patry schrieb:
> On Friday 11 September 2009 15:54:37 Oliver Demetz wrote:
>> Hi all
>>
>> First of all let me thank you all for this vital discussion on the topic.
>>
>> I have accepted grudginly that writing to the "Program Files" directory
>> is not really liked on Windows. ok.
>> So I followed Scott Aarons hint to use
>> QDesktopServices::storageLocation(QDesktopServices::DataLocation)
>>
>> BUT:
>> This still does not give me a location where all system users are
>> allowed to write (at least on my Windows 7 RC1 box), it gives me a path
>> inside the homedir of the current user!
>>
>> So my problems would now be solved if I could get somehow the same path
>> in the All Users directory tree.
>>
>> Any idea?
>
> What you are looking for is the "SHGetFolderPath()" function from the win32
> api.
>
> Pass-in this CSIDL: CSIDL_COMMON_APPDATA
>
> That will give you a path where all users can write and it will work on these
> OS.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list