PDA

View Full Version : How to open folder and file in place with admin status



Momergil
16th December 2011, 20:57
Hello!

I created a software that reads a file from a closed folder when it is started, but when it detects that the file and the folder don't exist, it creates a new one with predefined names.

The problem is that the software is hold in the C:program files (x86) folder, which is a place which require admin status for files and folder creation (and I don't know why I don't have that permission despite being administrator, but anyway). So what happens is that if I put the .exe plus .dll files in a common folder, the software runs ok, but when the software is put inside Program Files (x86), it doesn't open and the folder and the file is not created.

How should I proceed in this case? Is there a function in Qt or C++ that ask the user for permission and, once the permission is given, it would open the folder and create the file?

Thanks!


Momergil

Spitfire
19th December 2011, 09:46
I guess you have to run app as an administrator to get those permissions.

Right click on the app and select 'run as administrator' (on w7, vista will have something similar but I can't tell atm).

amleto
19th December 2011, 10:42
One solution is to make sure your folder location is somewhere less restricted, like 'my documents' or similar. I think you can do this with desktop services:

http://developer.qt.nokia.com/doc/qt-4.8/qdesktopservices.html

use storageLocation() and enum QDesktopServices::ApplicationsLocation