My application saves its settings under its executable folder, which happens to be where it is installed under Windows(C:\ProgramFiles). The problem I'm having is that I use fopen_s and open the file as binary but when my application saves the settings Windows doesn't allow it. I'm thinking it has to do something with permissions but I'm not sure where to look. Maybe I should change the directory to where it saves the settings to something like users/Documents.
Any thoughts on this, and why it isn't working? Why is fopen_s not allowed to save a file where my application is installed?
Applications running under normal user privileges have read-only access to the %ProgramFiles% directory. This is by design. If it was possible to save files to this directory, then multiple users sharing the same PC (with different accounts) would overwrite each other's settings file.
Adjust your code to save it's settings to the %LOCALAPPDATA% directory. Use SHGetKnownFolderPath API to get this directory path.
Related
i am storing a pdf file to c:\program files... through wpf (exe Installation) it is not allowing me to save that file due to Administrator permission,
But When i am storing same into D:\ drive it is working fine
Can any One give me the solution For it
The Program files directory requires adminstrative rights to be written in. This has nothing to do with WPF but is simply how Windows operates. Either you start your application as an Administrator or you get your application to show the UAC window to escalate privileges.
In my current project I like to use fopen or fopen_s to create a file via "w" option.
Using a QT GUI the user may choose any file name which is basically the return string of a file dialog - similar to what is known to windows dialogs.
QFileDialog::getSaveFileName(this,"Save as...","","all files (*.*)");
However, depending on the file name it gets created or not.
So for instance I can write files in my build directory 'C:/SVN/builds/GUI/temp.txt'
And I can create files on the windows desktop 'C:/Users/XXX/Desktop/temp.txt'
I can even create files in other build dirs 'C:/SVN/builds/foo/bin/Release/temp.txt'
But fopen doesn't let me create 'C:/temp.txt' and returns "access denied" (errorno 13)
my issue can be solved like described here: https://stackoverflow.com/a/4735652/2220850
but this effectively requires the user to have admin rights for my silly little tool to run properly.
so isn't there another way to get permissions to write the file the user selected from within the GUI?
Or is there at least for the user and me a way to know where on the disks our tool may or may not create files?
cheers
I don't think you can solve this in a clean way. There are folders that are forbidden to non-admin users. That's the way it is (without tweaking to OS settings).
Displaying your users a sensible error message like "Access denied (you may need admin rights to write to this directory, select a directory you may write to)" is probably the best way.
Read/write stuff where the shell/OS tells you you can/should do. Call the shell API to find out the correct path for Windows OS:
SHGetFolderPath()
SHGetKnownFolderPath()
I have inherited an air app, and I don't know a lot of the capabilities and limitations of air. Can I open a local from the current directory for read and write?
Using FileReference, I have been able to save a file to my /Documents directory. But is there way to have it just save in the current directory? Or have the prompt that currently comes up default to the current directory instead of my /Documents dir?
I've read http://livedocs.adobe.com/flex/3/html/help.html?content=Filesystem_08.html, and can't figure it out.
Thanks
If current directory happens to be application directory, then no. AIR has concept of various directories:
File.applicationDirectory - where app itself is installed, read-only.
File.applicationStorageDirectory - buried somewhere deep (on Windows, it is C:\Documents and Settings[User name]\Application Data[Application name]\Local Store) - you can use it to store files.
File.documentsDirectory - shortcut to current user's documents directory. Do not throw garbage there.
File.desktopDirectory - shortcut to user's desktop, should be treated even more carefully.
hi the win mobile 6 code tries to write files on network shared folder, but always gets UnauthorizedAccessException. I have checked permission and security setting on the folder and the code can read the file but just cant write to it. The code runs under administrator account which has full control over the folder and files. It is in vs 2008 professional with device emulator.Any help please? thanks very much.
You've verified that you can write the file outside of your program, correct? i.e. logged into a machine account and tried placing that specific file there.
Do you have access to the system that hosts the file? If so, you can check it's access logs to verify which account your app is using.
My guess would be that either your app isn't using the account you think it is, or that the admin account may doesn't actually have write access to that folder or file.
I have a program that works fine if UAC is turned off. I want to be able to use a manifest to have it simply request elevation privileges when it launches.
The instructions from MS say "The application manifest file should have the same name as the target executable file with a .manifest extension" and that's probably why I am not having any success.
http://msdn.microsoft.com/en-us/library/bb756929.aspx
My program is built as "one.exe" and then {SmartAssembly} renames it to "two.exe" and then the users are encouraged to rename it again. I can't tell if that matters or which executable name to use.
Does anyone know if what I want is even possible? If not, is there a way to have the app tell the user that the problem us UAC related?
Thanks in advance.
Embed the manifest as a resource inside your .exe