ClickOnce deployed application registry persmission issue
I have developed an application in C# with an option to run at Windows startup implemented using registry (current user hive). When I run my application fro开发者_如何学Gom VS or from the bin folder, this option works.
When I create ClickOnce installer (to be run from internet) and put it on Codeplex, after the application is installed this option does not work. No exception is thown, it just makes registry write. I suppose there is some kind of a security issue.
I tried to create a ClickOnce installer with the option to be run from a CD/local storage , after the application is installed it works. It just does not work after installing using the ClickOnce web installer (put on CodePlex).
I looked at the Publish settings, there are set to default = full trust. I really do not know what to do now to make the run at startup option work.
Create a second (console) application, that will preform the write, and add it to the references of you original application.
When your user starts the application, check if the registry key is set, if not run the before-mentioned console application with elevated rights. The user will be prompted for administration rights, and the write operation should succeed.
In your main app you have to add the reference to the console app. For easier assembly reference the console app should have at least 1 public class, so that you can get it type and the types assemlby and you thus don't have to use magic strings to get filenames. Example:
Process.Start(
new ProcessStartInfo
{
Verb = "runas",
FileName = typeof(SomeClassInOtherAssembly).Assembly.Location,
UseShellExecute = true,
CreateNoWindow = true // Optional....
}).WaitForExit();
I also found this nice blog post.
You should be able to write to HKCU (I am able to do this successfully). If you want to, post back the code that you are using to write the entry to the registry and I'll take a look.
EDIT
This blog article shows how to programmatically read and write to/from the registry. I have deployed this using ClickOnce, and it works fine.
http://robindotnet.wordpress.com/2010/05/31/enhanced-logging-in-clickonce-deployment/
Your code doesn't look out-of-whack to me, but you can try this code and see if it works (there are whole solutions in both VB and C# at the end of the article). If it does, there's something wrong with your code. If it doesn't work, then I don't know what to tell you.
精彩评论