简体   繁体   中英

Custom actions in a .NET Service Installer

I am writing a Windows Service in C# in Visual Studio 2010.

My service will require a registry key HKLM\\system\\currentcontrolset\\services\\myservicename\\parameters. It will also require a custom event source. I can't create either of these from within the service because both of these actions require running elevated on Win7, and I don't want my service to run elevated.

The event source seems to be created automagically (I wish I knew how/where and could find this documentation) by the installer.

What is the correct place for me to create and populate the Parameters registry key? Would it be the AfterInstall() event of the installer? I'd like to be able to roll back the installation if my actions fail and I'm not sure I can do that in AfterInstall().

AfterInstall is a good place; it happens after all Install methods, but before the Commit or Rollback logic, so if the install fails you can check to see if you created the key and remove it.

Remember to place similar logic to remove the key in the AfterUninstall event handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM