File Saving In Folder In Wpf - wpf

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.

Related

MSI and ClickOnce hybrid installer

Currently I have this scenario on my work. We are almost ready to deploy an image of Windows OS that includes some additional software.
I need to provide installers (MSI) of developed software but with the condition that this installer will install first the software and then the software behaviors as a clickonce deployed software.
I try to find any information on how to achieve this requirement, without succeed.
I did a workaround to achieve a installer that "install" a clickonce application.
Actually the installer creates a desktop shortcut referencing a .bat file that starts the .application from the server and after load the application and removes the desktop icon.
The bat file is simple:
del "%userprofile%\Desktop\{MyApplicationName}.lnk"
rundll32 user32.dll,UpdatePerUserSystemParameters
start \\ServerPath\MyApplicationClickOnceInstaller.application
The first line is responsible for deleting the shortcut from user desktop.
The second one is responsible for refreshing the user desktop.
Finally, the last one opens the .application file from the server.
Just put this .bat file as a file in the installer and create a shortcut that opens 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 run a WPF application on an other computer, as administrator

I have a C#/WPF application running inside Visual Studio on one computer. How can I run it on an other Windows computer, preferably without installing VisualStudio first? It needs administrator access, so I cannot use ClickOnce.
I know this is a really basic question, but I could not find it answered.
In Visual Studio right click on the project name and select "Open Folder in File Explorer" then enter the bin folder and the debug folder and you will find an exe file. Run it on the other computer by right clicking this exe and select "run as administrator"
If you want to make sure that an application runs with admin right, you should add an application manifest file (On your project : Add New Item -> Application Manifest File)
Inside this app.manifest, there is a node called requestedExecutionLevel. Its value should be changed like this :
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Once it's done and the application is built, you can take the .exe file generated and send it to the other computer. On the application launchup, the UAC should prompt to ask for admin privileges

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.

how to deploy Windows WPF Application?

I have a simple Windows Form application(WPF) with entity framework. After compiled, only a few files generated:
EntityFramework.dll
EntityFramework.xml
MyApp.exe
MyApp.application
MyApp.exe.config
...
Then I just copy following files to a network shared folder:
EntityFramework.dll
MyApp.exe
MyApp.exe.config
Then I can double click on MyApp.exe from developer computer the launch the app, but can not launch from another end user computer.
How to resolve this problem?
When you double click, app is not launching means certainly it is crashing so type the command eventvwr in run or cmd it'll open the Event viewer in that go to Windows Logs and Click on Application, you can see different levels of logs in that just find the last error log view the details it might help you
Have a look in the event log on the target computer and look at the error that is actually being reported.
It could be a missing installation of the correct version of the DotNet framework as suggested in the comments above, or it could also be that the execution policy of the target computer is preventing the user from running from a network drive (As a developer you probably have admin rights on your local pc allowing you to do this).
Whatever the actual cause you are always better to use some form of installer, rather than this form of putting files on the network (commonly known as xcopy deployment).
Probably the best solution is to use Visual studio to generate you a click once installer and publish it to your network drive. This will then copy the application locally on the users pc and run it from there.

Resources