Results 1 to 9 of 9

Thread: Prevent saving files to System folders

  1. #1
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Prevent saving files to System folders

    Hi All,

    I am creating a dialog based program that requires the user to save a text file to the hard drive.

    I have no problem saving my text file.

    My question is: Is there a standard way of preventing the user from saving to any system folders like C:\ or C:\Program Files on a windows system.

    Kind Regards

    Scott

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Prevent saving files to System folders

    You can probably intercept the directoryChanged signal, or whatever it's called, in an extension of the file dialog, then put up a warning and redirect away from the directories you don't want people to use.

    But this sort of thing is better addressed by the user or system administrator through file and directory permissions settings. In general, I don't like programs that circumvent my choices about where to put files.

  3. #3
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Prevent saving files to System folders

    My problem is that if I try to save the txt file to the users home directory everything saves fine.

    If I try to save the file to a location other that the users home directory (for eg. c:\Program Files\), the file is not saved to where I directed it. Instead it is saved to the "Virtual Store" ie (C:\Users\UsersName\AppData\Local\VirtualStore\Pro gram Files)

    I know that this is related to the fact that the user does not have the permissions to write to this location. Has anybody experienced this before, and what steps did you take to overcome this.

    Thanks in Advance

    Scott

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prevent saving files to System folders

    Check the permissions before opening the file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Prevent saving files to System folders

    Put a manifest into your Windows executable. This action will disable file system and registry virtualisation and attempts to write to prohibited areas should fail on Vista/Win 7.

  6. The following user says thank you to ChrisW67 for this useful post:

    ScottBrady (13th August 2011)

  7. #6
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Prevent saving files to System folders

    Hi Chris,

    Do you know of anywhere that there are some resource on the web where I can investigate how to do this, as I have never used a manifest file.

    Thanks

    Scott

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prevent saving files to System folders

    I'm sure MSDN is the right place to look for it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Prevent saving files to System folders

    You use the RC_FILE variable in your PRO file to name a Windows resource file to include into your executable (you need that for the Windows desktop icon anyway). That resource file, in turn, drags in a manifest file. Something like:

    myprog.pro:
    Qt Code:
    1. RC_FILE = myprog.rc
    To copy to clipboard, switch view to plain text mode 
    myprog.rc:
    Qt Code:
    1. ...
    2. CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "myprog.exe.manifest"
    3. ...
    To copy to clipboard, switch view to plain text mode 
    myprog.exe.manifest:
    Qt Code:
    1. <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    3. <assemblyIdentity version="1.0.0.0" processorArchitecture="X86"
    4. name="com.example.myprog" type="win32" />
    5. <description>My Prog</description>
    6. <dependency />
    7. <!-- Identify the application security requirements. -->
    8. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    9. <security>
    10. <requestedPrivileges>
    11. <requestedExecutionLevel
    12. level="asInvoker"
    13. uiAccess="false"/>
    14. </requestedPrivileges>
    15. </security>
    16. </trustInfo>
    17. <!-- padding to eight-byte multiple file size including BOM -->
    18. <!-- padding 123 -->
    19. </assembly>
    To copy to clipboard, switch view to plain text mode 

    Your manifest may vary, but the one above is typical for user apps. I am not sure if the file size requirement still exists (it avoided a bug).

  10. #9
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Prevent saving files to System folders

    Perfect !

    Thanks Chris.

    Exactly what I was looking for.

    Kind Regards and many thanks.

    Scott

Similar Threads

  1. Replies: 8
    Last Post: 15th May 2012, 05:21
  2. Qt select folders and files dialog.
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 13th July 2009, 08:53
  3. Replies: 1
    Last Post: 4th August 2008, 09:02
  4. viewing files or some folders
    By as001622 in forum Qt Programming
    Replies: 4
    Last Post: 2nd June 2008, 12:12
  5. How to manage files with different folders for make
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2007, 13:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.