Graphical installation program using VS Packers

table of Contents

background

During this time have been doing packager client program, you encounter various pits. Because no previous experience in this area, after a variety of toss, worked hard to finally complete.

Although there is not much technical content, but because of very tedious, they still look at this record.

Due to space reasons, first introduced the first stage: direct use VS comes with installation project packager.

Will continue to introduce later: Custom installation interface (NA windows default style), making use of NSIS script packager.

 

1. Establish installation project

1.1. Creating Project

First open your project will be packaged in VS. My case, my project called System.

Right-click Solution ->  Add  ->  New Project , below dialog box pops up.

We might name the new installation project called SetupSystem.

 

1.2 Setting installation project properties

Select the installation project, set some parameters in its properties bar.

Author - Developers

Manufacturer - Software manufacturers

These two are the default signature of Microsoft Corporation.

ProductName - Name

Version - release. After changes to the version number, the UpgradeCode will change.

 

1.3. Set the default installation path

Select the Applications folder , view the properties bar.

As shown below, the default installation path is: ProgramFiles generated manufacturer name + path name + product.

For example, if I follow the steps (2) to set the default installation path name would be: C: \ Program Files (x86) \ zp \ System \.

If you do not want to display the name of the manufacturer, you can [Manufacturer] Delete this parameter.

 

2. Add the installation file

( 1 ) Add Project Output

In the File System column there are three paths: the application folder , the user's " Programs" menu , the user's desktop .

Applications folder and correspond exactly to the installation directory; users "Programs" menu and user desktops must have no more than explain it.

First Double-click the Applications folder, where you add content to the installation directory.

Open the context menu, click  Add  ->  Project Output , pop Add Project Output Group menu.

选中主输出,点击确定。VS自动导入程序的exe文件和程序依赖的DLL文件。

 

2)添加资源文件

当然,你可能还需要添加资源文件。

有两种方法:

一种是,打开右键菜单,点击 添加,选择你要添加的文件、文件夹等资源。需要注意的是保持目录结构和你期望的安装根目录结构一致。

还有一种方法更简单,直接复制、拖拽你想添加的资源文件或文件夹到应用程序文件夹中。

 

3.   添加卸载程序

即在添加你的应用程序项目的时候,多添加一个msiexec.exe进去,这个文件在c:\windows\system32文件夹下。

msiexec.exe这个执行文件用于安装Windows Installer安装包(msi格式的文件)。

 

4.   创建快捷方式

4.1. 添加快捷方式

右击可执行文件和msiexec.exe为它们添加快捷方式。

在快捷方式的属性栏中,可以在Icon项中为其设置一个ico格式的图标。

 

4.2. 设置msiexec快捷方式的参数

对于msiexec.exe的快捷方式,需要设置一些参数,才能正常卸载安装的程序。

步骤如下:

选中安装工程,在属性栏中拷贝ProductCode项的值。

 

然后打开你创建的那个快捷方式的属性对话框,

在Aguements属性中输入"/x {ProductCode}",

 

安装程序后,打开注册表,可以查看到卸载信息。

以我的机器(64位操作系统)为例,在

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{产品码}可以看到下图信息。

:如果是32位,应该是HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\Windows\CurrentVersion\Uninstall\{产品码}

 

4.3. 为用户的“程序”菜单和用户桌面添加快捷方式

将执行文件的快捷方式分别拷贝到用户的程序”菜单用户桌面

将卸载程序的快捷方式拷贝到用户的程序”菜单

 

5.   添加依赖项

选中安装项目工程,打开右键菜单,点击属性,弹出属性对话框。

点击系统必备,弹出系统必备对话框。

输出文件名项中可以设置输出文件的路径,安装程序最后会输出到这个路径下。

 

选中要添加的必备组件,点击确定

注意,安装必备组件有三种方式:

1.       安装的时候会从供应商的官网上下载对应组件。

2.       直接将组件打包到安装程序文件中,省去下载的功夫。

3.       指定一个路径去下载对应组件。

 

最后,选中安装项目工程,打开右键菜单,点击生成,就会自动生成安装程序了。

生成的安装程序文件如下图

 

6.   添加注册表

(1)       在“解决方案资源管理器”窗口中选中安装项目,单击鼠标右键,在弹出的对话框中选择“视图/注册表”选项,如图:

(2)       在“注册表”选项卡中,可以在HKRY_CURRENT_USER/SoftwareHKRY_CURRENT_MACHINE/Software下添加键值,当然节点名也是可以重命名的。

单击鼠标右键,在弹出的对话框中选择“新建/字符串值”选项。

如图:我设置了一个名为key1的键,值为”Hello World”

(4)选中添加的注册表项值,单击鼠标右键,选择“属性窗口”选项,弹出“属性”窗口,如图,这里可以对注册表项的值作修改。

按照以上步骤,就可以为安装程序添加一个注册表项。在程序安装成功后,查看注册表,可以看到到我们写入的键值。

 

7.   添加、修改安装页面

VS支持对安装程序添加、修改安装页面。但是我在尝试中发现,不够灵活。只能使用默认的样式风格。在这里,我大致的介绍一下。

7.1. 打开用户界面视图

选中安装项目,打开右键菜单,点击 视图 -> 用户界面

 

7.2. 添加对话框

在用户界面视图中,选中 启动,打开右键菜单,点击 添加对话框

 

选择想要添加的对话框,如下图:

选中一个对话框,还可以调整它的执行顺序。如下图:

至于每个对话框的属性设置,在这里不再赘述,有兴趣的朋友可以自己折腾一下。

 

参考资料

http://blog.sina.com.cn/s/blog_473b385101019ufr.html

http://jingyan.baidu.com/article/e8cdb32b871eaa37052badd1.html

Guess you like

Origin www.cnblogs.com/aimei/p/12201603.html