安装应用程序C#时的注册表更改 [英] Registry change upon installing application C#

查看:99
本文介绍了安装应用程序C#时的注册表更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次尝试使用Visual Studio为应用程序制作安装软件包.我有一个注册表值,在安装该程序时需要更改该注册表值,我需要在每次计算机启动时都启动该程序.

Just about to try and make an install package for an app for that first time with visual studio. I have a registry value that needs to be changed when the program is installed I need the program to start everytime the computer starts.

这是一个相当琐碎的任务吗?有人可以指出我要尝试实现的目标.

Is this a fairly trivial task? Could someone point me towards something to try and achieve this.

到目前为止,我只拥有带有表单等的应用程序.

So far I just have the app with it's forms etc.

推荐答案

我有同样的问题,我正在使用 WIX ,然后按照中的答案进行操作Stackoverflow问题.我也是WIX的新手,如果您感兴趣的话,这是我完整的WIX工作脚本(在Windows XP和Windows 8.1上进行了测试):

I have same problem, I'm using WIX and follow the answer from this Stackoverflow question. I'm also new on WIX, here's my full WIX working script if you might interest (tested on Windows XP & Windows 8.1):

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

<Product Id="*" 
       Name="FooSetup" Language="1033"
       Version="1.0.1.1" 
       Manufacturer="Foo Enterprise" 
       UpgradeCode="9235c293-2f08-4c2b-b7a5-69d01f5fca32">

    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />


    <!-- Step 1: Define the directory structure -->
    <Directory Id="TARGETDIR" Name="SourceDir">

       <Directory Id="ProgramFilesFolder">
          <Directory Id="INSTALLFOLDER" Name="FooSetup" />
       </Directory>

       <Directory Id="ProgramMenuFolder">
          <Directory Id="ApplicationProgramsFolder" Name="Foo Application"/>
       </Directory>

       <Directory Id="DesktopFolder" Name="Desktop" />

    </Directory>

    <!-- Step 2: Add files to your installer package & add autostart feature -->
    <DirectoryRef Id="INSTALLFOLDER">

       <!-- The main executable file-->
       <Component Id="FooApplication" Guid="3F122E60-3745-4AEB-ADA3-B90DCB87E0BD">
          <File Id="FooMainApp" Source="$(var.Foo.TargetPath)" KeyPath="yes"/>
       </Component>

       <!-- The main lib file-->
       <Component Id="FooLib" Guid="83BEDB02-C9F5-4A06-B3D5-0A4D61D6A99C">
          <File Id="FooFileLib" Source="$(var.Foo.Lib.TargetPath)" KeyPath="yes"/>
       </Component>

       <!-- Register windows autostart registry -->
       <Component Id="RegistryEntries" Guid="45C7AC46-1101-4301-83E1-D24392283A60">
          <RegistryValue Type="string"
                   Name="FooStartup"
                   Value="[#FooMainApp]"
                   Root="HKLM"
                   Key="Software\Microsoft\Windows\CurrentVersion\Run"
                   Action="write"/>
       </Component>
    </DirectoryRef>

    <!-- Step 3: Add the shortcut to your installer package -->

    <!-- Start Menu -->
    <DirectoryRef Id="ApplicationProgramsFolder">
       <Component Id="FooShortcutMenu" Guid="3874D005-4E1C-4C0E-9CEA-8CD8D5442B60">
          <Shortcut Id="FooApplicationStartMenuShortcut"
              Name="Foo Application"
              Description="The Foo is Cool!"
              Target="[#FooMainApp]"
              WorkingDirectory="INSTALLFOLDER"/>
          <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
          <RegistryValue Root="HKCU" Key="Software\Microsoft\FooApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
       </Component>
    </DirectoryRef>

    <!-- Desktop Menu -->
    <DirectoryRef Id="DesktopFolder">
       <Component Id="FooDesktopShortcutMenu" Guid="D4D0A2ED-C0DB-4524-AC53-D30F904DB846">
          <Shortcut Id="FooApplicationDesktopShortcut"
              Name="Foo Application"
              Description="The Foo is Cool!"
              Target="[#FooMainApp]"
              WorkingDirectory="INSTALLFOLDER"
              Directory="DesktopFolder"/>
          <RemoveFolder Id="DesktopFolder" On="uninstall"/>
          <RegistryValue Root="HKCU" Key="Software\Microsoft\FooApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
       </Component>
    </DirectoryRef>

    <!-- Tell Wix -->
    <Feature Id="ProductFeature" Title="FooSetup" Level="1">
       <ComponentRef Id="FooApplication" />
       <ComponentRef Id="FooLib" />
       <ComponentRef Id="FooShortcutMenu"/>
       <ComponentRef Id="FooDesktopShortcutMenu"/>
       <ComponentRef Id="RegistryEntries" />
    </Feature>
</Product>
</Wix>

这篇关于安装应用程序C#时的注册表更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆