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
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.
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
Re: Prevent saving files to System folders
Check the permissions before opening the file.
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.
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
Re: Prevent saving files to System folders
I'm sure MSDN is the right place to look for it.
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:
Code:
RC_FILE = myprog.rc
myprog.rc:
Code:
...
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "myprog.exe.manifest"
...
myprog.exe.manifest:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86"
name="com.example.myprog" type="win32" />
<description>My Prog</description>
<dependency />
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<!-- padding to eight-byte multiple file size including BOM -->
<!-- padding 123 -->
</assembly>
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).
Re: Prevent saving files to System folders
Perfect !
Thanks Chris.
Exactly what I was looking for.
Kind Regards and many thanks.
Scott