DotNet程序打包
.Net程序制作安装包,打包.net framework ,在没有安装.net机器上检测安装。试用过很多打包软件,只有这款Setup Factory比较合心意,使用又简单。
软件名称:Setup Factory
所用版本:7.0.1
【软件介绍】
Setup Factory 是一个强大的安装程序制作工具。提供了安装制作向导界面,即使你对安装制作不了解,也可以生成专业性质的安装程序。可建立快捷方式,也可直接在 Windows 系统的注册表加入内容,还能在 Win.ini 和 System.ini 内加入设定值,更可以建立反安装选项等等。它内附的向导可以一步步的带领您做出漂亮又专业的安装程序。
1.首先找到Setup Factory安装目录下的Dependencies目录,在目录中新建一个dotnet2_0.xml的文件
2.然后,在Dependencies目录下新建子目录,取名dotnet2_0,将.NET FRAMEWORK安装程序dotnetfx.exe拷至该子目录下,dotnetfx.exe可在VS 2005的安装目录下的SDK\v2.0\BootStrapper\Packages\dotnetfx目录下找到。
3.完成之后打开Setup Factory,选择:资源---从属---添加,可以看到.NET FRAMEWORK 2.0了。
附dotnet2_0.xml:
<DependencyTemplate>
<Dependency>
<Name>Microsoft .NET Framework 2.0</Name>
<RuntimeTempFolder>dotnet2_0</RuntimeTempFolder>
<RevisionDate>Friday, March 30, 2007</RevisionDate>
<Description>安装 Microsoft .NET Framework 2.0应用程序所需的运行时文件。</Description>
<DetectScript>
function isDotNet_Installed()
--author:zhengxinhe www.admans.net
-- Output to the log that the .NET detection has started.
SetupData.WriteToLogFile("Success\\t.NET 2.0 Module: Detection script started.\\r\\n", true);
-- Get the operating system name.
--Check to see if the registry key exists
DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\\\\Microsoft\\\\.NETFramework");
if (DotNet_Registry == nil) then
-- The registry key does not exist
-- Run the .NET Installation script
-- Output to the log file that .NET could not be found, so it will be installed.
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: No version of .NET 2.0 files was found. .NET 2.0 will be installed.\\r\\n", true);
return false;
end
-- The key does exist
-- Get the .NET install location from the registry
DotNet_Install_Location = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\\\Microsoft\\\\.NETFramework", "InstallRoot", true);
-- Look for the file mscorcfg.dll
Does_File_Exist = DotNet_Install_Location.."\\\\v2.0.50727\\\\aspnet_rc.dll";
if(not File.DoesExist(Does_File_Exist))then
-- The file does not exist
-- Run the .NET Installation script
-- Output to the log file that .NET could not be found, so it will be installed.
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: No version of .NET 2.0 file was found. .NET 2.0 will be installed.\\r\\n", true);
return false;
end
-- The file does exist
-- Get the version of mscorcfg.dll
msc_ver = File.GetVersionInfo(Does_File_Exist);
if(not msc_ver)then
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: no version was found. .NET 2.0 will be installed.\\r\\n", true);
return false;
end
-- Compare the returned value against the needed value
Compare = String.CompareFileVersions(msc_ver.FileVersion, "2.0.50727.42");
if (Compare == -1) then
-- Output to the log file that a lesser version of .NET was found on the system
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: A lesser version of .NET 2.0("..msc_ver.FileVersion..") was found on the users system.\\r\\n", true);
return false;
else
-- a version less than version 2.0 is installed
-- Output to the log file that a lesser version of .NET was found on the system
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: A new or this version of .NET 2.0 was found on the users system.\\r\\n", true);
return true;
end
end
</DetectScript>
<DetectFunction>isDotNet_Installed</DetectFunction>
<InstallScript>
-- 用在安装操作中的变量:
local strMessage = [[安装程序检测到你的系统没有安装Microsoft .NET Framework2.0或者版本过旧。请点击“确定”进行安装,点击“取消”中止安装。]];
local strDialogTitle = "必需的技术文件";
local bShowUserPrompt = true; -- 设置为 true 来询问用户是否安装模块
local bRunInstallFile = true; -- 设置默认选择 (是否默认运行安装)
local strRuntimeSupportFolder = SessionVar.Expand("%TempLaunchFolder%\\\\dotnet2_0");
local strFileToRun = strRuntimeSupportFolder.."\\\\dotnetfx.exe";
-----------------------------------------------------------------------------------------
-- 安装已启动。
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:安装脚本已启动。\\r\\n", true);
-- 删除临时文件和运行时支持文件夹 (同时进行错误检查)
local function PerformCleanUp()
File.Delete(strFileToRun);
error = Application.GetLastError();
if error ~= 0 then
SetupData.WriteToLogFile("错误\\tdotnet2_0 模块:无法删除临时文件 (".._tblErrorMessages[error]..")\\r\\n", true);
end
Folder.Delete(strRuntimeSupportFolder);
error = Application.GetLastError();
if error ~= 0 then
SetupData.WriteToLogFile("错误\\tdotnet2_0模块:无法删除临时文件夹 (".._tblErrorMessages[error]..")\\r\\n", true);
end
end
-- 是否显示对话框来询问用户是否安装模块。
if(bShowUserPrompt)then
local nDialogResult = Dialog.Message(strDialogTitle,strMessage,MB_OKCANCEL,MB_ICONEXCLAMATION);
if(nDialogResult == IDOK)then
-- 用户选择安装模块。
bRunInstallFile = true;
-- 用户要安装它
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:用户已确认,准备安装。\\r\\n", true);
else
-- 用户不安装模块。
bRunInstallFile = false;
-- 用户回答否
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:用户不安装模块。\\r\\n", true);
end
end
-- 检查用户是否要安装运行时。
if(bRunInstallFile)then
-- 开始!
SetupData.WriteToLogFile("成功\\tdotnet2_0模块:正在运行dotnet2_0 安装程序。\\r\\n", true);
-- “/R:N”命令行参数告诉 VB 安装程序若需要的话不要显示重启屏幕。
-- 我们将检测整个安装进程返回代码,若需要的话,还设置内部 _NeedsReboot 变量。
-- 【注意】在静默方式下,你不能添加命令行参数“/Q”来运行安装
local nResult = File.Run(strFileToRun,"/R:N","",SW_SHOWNORMAL,true);
if(nResult == 3010)then
-- VB 安装指明它需要重启才能完成
-- 设置 Setup Factory 的重启变量,以便在安装结束时重启
_NeedsReboot = true;
-- 需要重启
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:dotnet2_0 安装程序已告知它需要重启。\\r\\n", true);
end
-- 删除运行时安装程序文件,并删除临时文件夹
PerformCleanUp();
-- 全部完成!
SetupData.WriteToLogFile("成功\\tdotnet2_0模块:dotnet2_0运行时安装完毕。\\r\\n", true);
else
-- 用户不想安装运行时,那么删除运行时安装程序文件,
-- 并删除临时文件夹,然后退出安装程序。
PerformCleanUp();
-- 全部完成!
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:dotnet2_0 运行时未安装。\\r\\n", true);
Application.Exit();
end
</InstallScript>
<SupportFiles>
<File>#SUFDIR#\\Dependencies\\dotnet2_0\\dotnetfx.exe</File>
</SupportFiles>
</Dependency>
</DependencyTemplate>
<Dependency>
<Name>Microsoft .NET Framework 2.0</Name>
<RuntimeTempFolder>dotnet2_0</RuntimeTempFolder>
<RevisionDate>Friday, March 30, 2007</RevisionDate>
<Description>安装 Microsoft .NET Framework 2.0应用程序所需的运行时文件。</Description>
<DetectScript>
function isDotNet_Installed()
--author:zhengxinhe www.admans.net
-- Output to the log that the .NET detection has started.
SetupData.WriteToLogFile("Success\\t.NET 2.0 Module: Detection script started.\\r\\n", true);
-- Get the operating system name.
--Check to see if the registry key exists
DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\\\\Microsoft\\\\.NETFramework");
if (DotNet_Registry == nil) then
-- The registry key does not exist
-- Run the .NET Installation script
-- Output to the log file that .NET could not be found, so it will be installed.
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: No version of .NET 2.0 files was found. .NET 2.0 will be installed.\\r\\n", true);
return false;
end
-- The key does exist
-- Get the .NET install location from the registry
DotNet_Install_Location = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\\\Microsoft\\\\.NETFramework", "InstallRoot", true);
-- Look for the file mscorcfg.dll
Does_File_Exist = DotNet_Install_Location.."\\\\v2.0.50727\\\\aspnet_rc.dll";
if(not File.DoesExist(Does_File_Exist))then
-- The file does not exist
-- Run the .NET Installation script
-- Output to the log file that .NET could not be found, so it will be installed.
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: No version of .NET 2.0 file was found. .NET 2.0 will be installed.\\r\\n", true);
return false;
end
-- The file does exist
-- Get the version of mscorcfg.dll
msc_ver = File.GetVersionInfo(Does_File_Exist);
if(not msc_ver)then
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: no version was found. .NET 2.0 will be installed.\\r\\n", true);
return false;
end
-- Compare the returned value against the needed value
Compare = String.CompareFileVersions(msc_ver.FileVersion, "2.0.50727.42");
if (Compare == -1) then
-- Output to the log file that a lesser version of .NET was found on the system
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: A lesser version of .NET 2.0("..msc_ver.FileVersion..") was found on the users system.\\r\\n", true);
return false;
else
-- a version less than version 2.0 is installed
-- Output to the log file that a lesser version of .NET was found on the system
SetupData.WriteToLogFile("Info\\t.NET 2.0 Module: A new or this version of .NET 2.0 was found on the users system.\\r\\n", true);
return true;
end
end
</DetectScript>
<DetectFunction>isDotNet_Installed</DetectFunction>
<InstallScript>
-- 用在安装操作中的变量:
local strMessage = [[安装程序检测到你的系统没有安装Microsoft .NET Framework2.0或者版本过旧。请点击“确定”进行安装,点击“取消”中止安装。]];
local strDialogTitle = "必需的技术文件";
local bShowUserPrompt = true; -- 设置为 true 来询问用户是否安装模块
local bRunInstallFile = true; -- 设置默认选择 (是否默认运行安装)
local strRuntimeSupportFolder = SessionVar.Expand("%TempLaunchFolder%\\\\dotnet2_0");
local strFileToRun = strRuntimeSupportFolder.."\\\\dotnetfx.exe";
-----------------------------------------------------------------------------------------
-- 安装已启动。
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:安装脚本已启动。\\r\\n", true);
-- 删除临时文件和运行时支持文件夹 (同时进行错误检查)
local function PerformCleanUp()
File.Delete(strFileToRun);
error = Application.GetLastError();
if error ~= 0 then
SetupData.WriteToLogFile("错误\\tdotnet2_0 模块:无法删除临时文件 (".._tblErrorMessages[error]..")\\r\\n", true);
end
Folder.Delete(strRuntimeSupportFolder);
error = Application.GetLastError();
if error ~= 0 then
SetupData.WriteToLogFile("错误\\tdotnet2_0模块:无法删除临时文件夹 (".._tblErrorMessages[error]..")\\r\\n", true);
end
end
-- 是否显示对话框来询问用户是否安装模块。
if(bShowUserPrompt)then
local nDialogResult = Dialog.Message(strDialogTitle,strMessage,MB_OKCANCEL,MB_ICONEXCLAMATION);
if(nDialogResult == IDOK)then
-- 用户选择安装模块。
bRunInstallFile = true;
-- 用户要安装它
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:用户已确认,准备安装。\\r\\n", true);
else
-- 用户不安装模块。
bRunInstallFile = false;
-- 用户回答否
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:用户不安装模块。\\r\\n", true);
end
end
-- 检查用户是否要安装运行时。
if(bRunInstallFile)then
-- 开始!
SetupData.WriteToLogFile("成功\\tdotnet2_0模块:正在运行dotnet2_0 安装程序。\\r\\n", true);
-- “/R:N”命令行参数告诉 VB 安装程序若需要的话不要显示重启屏幕。
-- 我们将检测整个安装进程返回代码,若需要的话,还设置内部 _NeedsReboot 变量。
-- 【注意】在静默方式下,你不能添加命令行参数“/Q”来运行安装
local nResult = File.Run(strFileToRun,"/R:N","",SW_SHOWNORMAL,true);
if(nResult == 3010)then
-- VB 安装指明它需要重启才能完成
-- 设置 Setup Factory 的重启变量,以便在安装结束时重启
_NeedsReboot = true;
-- 需要重启
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:dotnet2_0 安装程序已告知它需要重启。\\r\\n", true);
end
-- 删除运行时安装程序文件,并删除临时文件夹
PerformCleanUp();
-- 全部完成!
SetupData.WriteToLogFile("成功\\tdotnet2_0模块:dotnet2_0运行时安装完毕。\\r\\n", true);
else
-- 用户不想安装运行时,那么删除运行时安装程序文件,
-- 并删除临时文件夹,然后退出安装程序。
PerformCleanUp();
-- 全部完成!
SetupData.WriteToLogFile("成功\\tdotnet2_0 模块:dotnet2_0 运行时未安装。\\r\\n", true);
Application.Exit();
end
</InstallScript>
<SupportFiles>
<File>#SUFDIR#\\Dependencies\\dotnet2_0\\dotnetfx.exe</File>
</SupportFiles>
</Dependency>
</DependencyTemplate>
操作注册表
在定制安装界面中,可以添加一个界面,选择界面类型,并且能够自定义界面上的操作事件,比如在OnPreload、OnNext、OnBack、OnCancel、OnHelp编写脚本以实现特定的功能,下面的代码是实现在自定义的配置设置界面中用户填写完配置信息后,点“下一步”时,将填写的信息写入到注册表,其中CTRL_EDIT_01等为编辑控件(这里是文本框)的ID。
在定制安装界面中,可以添加一个界面,选择界面类型,并且能够自定义界面上的操作事件,比如在OnPreload、OnNext、OnBack、OnCancel、OnHelp编写脚本以实现特定的功能,下面的代码是实现在自定义的配置设置界面中用户填写完配置信息后,点“下一步”时,将填写的信息写入到注册表,其中CTRL_EDIT_01等为编辑控件(这里是文本框)的ID。
-- 这些操作在点击“下一步”按钮时执行。
-- 提示:你可以在这里添加验证用户输入信息的操作
Registry.CreateKey(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem");
tEditFieldServer = DlgEditField.GetProperties(CTRL_EDIT_01);
tEditFieldDBUser = DlgEditField.GetProperties(CTRL_EDIT_02);
--Debug.ShowWindow( true );
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "ServerName", tEditFieldServer.Text, REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "DBUser", DlgEditField.GetProperties(CTRL_EDIT_02).Text, REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "DBPwd", DlgEditField.GetProperties(CTRL_EDIT_03).Text, REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "DBName", DlgEditField.GetProperties(CTRL_EDIT_04).Text, REG_SZ);
Debug.Print(tEditFieldServer.Text);
test = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "ServerName", true);
Debug.Print(test);
-- 进入下一个屏幕
Screen.Next();
-- 提示:你可以在这里添加验证用户输入信息的操作
Registry.CreateKey(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem");
tEditFieldServer = DlgEditField.GetProperties(CTRL_EDIT_01);
tEditFieldDBUser = DlgEditField.GetProperties(CTRL_EDIT_02);
--Debug.ShowWindow( true );
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "ServerName", tEditFieldServer.Text, REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "DBUser", DlgEditField.GetProperties(CTRL_EDIT_02).Text, REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "DBPwd", DlgEditField.GetProperties(CTRL_EDIT_03).Text, REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "DBName", DlgEditField.GetProperties(CTRL_EDIT_04).Text, REG_SZ);
Debug.Print(tEditFieldServer.Text);
test = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\FengcheSoft\TradeSystem", "ServerName", true);
Debug.Print(test);
-- 进入下一个屏幕
Screen.Next();