2

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 from 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.

Igor Kulman
  • 16,211
  • 10
  • 57
  • 118

1 Answers1

3

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.

Community
  • 1
  • 1
m0sa
  • 10,712
  • 4
  • 44
  • 91
  • Works fine on Windows 7. On Windows XP I am propted to choose a user to run the console application as, I choose the current user (local administrator) and the console application crashes on "Unable to find a version of the runtime to run this application" – Igor Kulman Jan 19 '11 at 14:27