write file in network shared folder with UnauthorizedAccessException? - file

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.

Related

UWP on Windows 1903 broadFileSystemAccess access denied on Drive D

broadFileSystemAccess works as expected when accessing files on Drive C, however, as soon as I try to access files on another Drive, I get access denied
Without broadFileSystemAccess, load a file from the Desktop. Access Denied as expected.
With broadFileSystemAccess, load a file from the Desktop. Access Granted as expected.
With broadFileSystemAccess, load a file from the Drive D. Access Denied not expected.
Dim file = Await Windows.Storage.StorageFile.GetFileFromPathAsync("D:\TestFile.txt")
I should be able to access any drive. My system has 4 drives and a NAS, only Drive C is accessable using broadFileSystemAccess.
What do I need to do to allow my app to access files on other drives; this is the only thing holding me back from porting my WPF apps.
Thanks in advance
I'm going to close this. I updated to the latest patch today and it's fixed. The prompt to ask a user to allow the app file system permissions is still broken (e.g. it doesn't prompt still), but the access to files on other drives is now working.
Additional info: I also created new C# and vb.net apps to test the theory and they work as expected, I then went back to the failing project and it's now working - hence me assuming the patch fixed it.

Calling an application with elevated Privileges from a normal privileged account from normal application causing issue when placed in Program Files

I have a program that needs to run with normal privileges. To prevent piracy, at the launch of our application we launch a License Manager application that needs to run with Elevated Privileges. Upon enquiring with our vendors, the License Manager seems to have this elevated privileges added in its app.manifest file which is necessary to read some kind of Disk ID information, so it is mandatory (we cannot reduce its privilege requirements).
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
The application successfully launches the License Manager if it is placed in a normal folder. However when it is placed in Program Files folder, it seems to close at launch with no intimation.
We also checked running the application with normal credentials without adding the License Manager (it works fine).
Do we need some sort of settings to be changed either in registry or in some other windows settings to enable launching elevated privileged application from normal account. Or perhaps some code snippet needs to be added at the code launch section which can enable this scenario.
We have even tried pasting the folder created in Program Files to the Desktop (it also runs fine).
OS: Windows 7
Please let me know if any additional information is needed form my side. Any help in this direction is appreciated.
My Humble appologies for assuming problem with Program Files Directory.
It turned out that the logs written by the License Manager were being written in the current application execution folder. The problem was caused by trying to write the log to Program Files folder when the appliction did not have the permissions to write a text file to this folder.
The logging logic was shared between the License Manager (from the program we called a function that was defined in the License Manager, which was writing logs) and the application running from the Program Files folder.
We changed the log creation folder to AppData folder. This has caused the applicaiton to launch successfully.
Cause Conclusion:
Writing log file in Program Files folder from an application that did not have admin privilege.
Note: I have added this post and this answer purely to help other like me, in case they dont have a solution in this type of scenario.

How to write files in C:\Windows\System32 with full permissions

Iam working on POS software using winforms. Iam trying to programmatically writing XML file (which contain some encrypted information about software serial number) to C:\Windows\System32 directory. But when i write i get an error Access denied.
Can anyone please explain how can i write this file with full permissions in this directory in windows 7 as well as in windows XP???
Any other suggestion or better way to do this will also be welcome.
Thanks in advance.
You'll need to be an administrator on the machine to write to the Windows directory. In addition, on Vista and later, your process will need to be "elevated" (otherwise known as Run As Administrator). You can configure this on your application's property sheet, as discussed here, or with a bit more work, do it programmatically.
It's bad practice to write to that directory, though, notwithstanding all the (misguided) software that does that. Save your files somewhere else. %appdata% or %localappdata% (directories specifically meant for application data) are good choices.

saving file in "Program Files/myApplication" folder with fopen_s

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.

UAC Application Manifest when you don't know runtime application name

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

Resources