Setup Factory 7.0打包.NET FRAMEWORK
系統
2534 0
本文介紹一個工具:Setup Factory。在7.0版本中,Setup Factory的默認從屬資源中僅支持VB5.0及VB6.0,想要在生成的安裝程序中自動完成.NET FRAMEWORK的安裝,從網上查了一下,須要按以下步驟做幾件事:
首先找到Setup Factory安裝目錄下的Dependencies目錄,在目錄中新建一個dotnet2_0.xml的文件。
然后,在Dependencies目錄下新建子目錄,取名dotnet2_0,將.NET FRAMEWORK安裝程序dotnetfx.exe拷至該子目錄下,dotnetfx.exe可在VS 2005的安裝目錄下的SDK//v2.0//BootStrapper//Packages//dotnetfx目錄下找到。
完成之后打開Setup Factory,選擇:資源---從屬---添加,可以看到.NET FRAMEWORK 2.0了。
文件dotnet2_0.xml內容如下:
<
DependencyTemplate
>
<
Dependency
>
<
Name
>
Microsoft.NETFramework2.0
</
Name
>
<
RuntimeTempFolder
>
dotnet2_0
</
RuntimeTempFolder
>
<
RevisionDate
>
Friday,March30,2007
</
RevisionDate
>
<
Description
>
安裝Microsoft.NETFramework2.0應用程序所需的運行時文件。
</
Description
>
<
DetectScript
>
functionisDotNet_Installed()
--author:zhengxinhewww.admans.net
--Outputtothelogthatthe.NETdetectionhasstarted.
SetupData.WriteToLogFile("Success/t.NET2.0Module:Detectionscriptstarted./r/n",true);
--Gettheoperatingsystemname.
--Checktoseeiftheregistrykeyexists
DotNet_Registry=Registry.DoesKeyExist(HKEY_LOCAL_MACHINE,"Software//Microsoft//.NETFramework");
if(DotNet_Registry==nil)then
--Theregistrykeydoesnotexist
--Runthe.NETInstallationscript
--Outputtothelogfilethat.NETcouldnotbefound,soitwillbeinstalled.
SetupData.WriteToLogFile("Info/t.NET2.0Module:Noversionof.NET2.0fileswasfound..NET2.0willbeinstalled./r/n",true);
returnfalse;
end
--Thekeydoesexist
--Getthe.NETinstalllocationfromtheregistry
DotNet_Install_Location=Registry.GetValue(HKEY_LOCAL_MACHINE,"Software//Microsoft//.NETFramework","InstallRoot",true);
--Lookforthefilemscorcfg.dll
Does_File_Exist=DotNet_Install_Location.."http://v2.0.50727//aspnet_rc.dll";
if(notFile.DoesExist(Does_File_Exist))then
--Thefiledoesnotexist
--Runthe.NETInstallationscript
--Outputtothelogfilethat.NETcouldnotbefound,soitwillbeinstalled.
SetupData.WriteToLogFile("Info/t.NET2.0Module:Noversionof.NET2.0filewasfound..NET2.0willbeinstalled./r/n",true);
returnfalse;
end
--Thefiledoesexist
--Gettheversionofmscorcfg.dll
msc_ver=File.GetVersionInfo(Does_File_Exist);
if(notmsc_ver)then
SetupData.WriteToLogFile("Info/t.NET2.0Module:noversionwasfound..NET2.0willbeinstalled./r/n",true);
returnfalse;
end
--Comparethereturnedvalueagainsttheneededvalue
Compare=String.CompareFileVersions(msc_ver.FileVersion,"2.0.50727.42");
if(Compare==-1)then
--Outputtothelogfilethatalesserversionof.NETwasfoundonthesystem
SetupData.WriteToLogFile("Info/t.NET2.0Module:Alesserversionof.NET2.0("..msc_ver.FileVersion..")wasfoundontheuserssystem./r/n",true);
returnfalse;
else
--aversionlessthanversion2.0isinstalled
--Outputtothelogfilethatalesserversionof.NETwasfoundonthesystem
SetupData.WriteToLogFile("Info/t.NET2.0Module:Aneworthisversionof.NET2.0wasfoundontheuserssystem./r/n",true);
returntrue;
end
end
</
DetectScript
>
<
DetectFunction
>
isDotNet_Installed
</
DetectFunction
>
<
InstallScript
>
--用在安裝操作中的變量:
localstrMessage=[[安裝程序檢測到你的系統沒有安裝Microsoft.NETFramework2.0或者版本過舊。請點擊“確定”進行安裝,點擊“取消”中止安裝。]];
localstrDialogTitle="必需的技術文件";
localbShowUserPrompt=true;--設置為true來詢問用戶是否安裝模塊
localbRunInstallFile=true;--設置默認選擇(是否默認運行安裝)
localstrRuntimeSupportFolder=SessionVar.Expand("%TempLaunchFolder%//dotnet2_0");
localstrFileToRun=strRuntimeSupportFolder.."http://dotnetfx.exe";
-----------------------------------------------------------------------------------------
--安裝已啟動。
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:安裝腳本已啟動。/r/n",true);
--刪除臨時文件和運行時支持文件夾(同時進行錯誤檢查)
localfunctionPerformCleanUp()
File.Delete(strFileToRun);
error=Application.GetLastError();
iferror~=0then
SetupData.WriteToLogFile("錯誤/tdotnet2_0模塊:無法刪除臨時文件(".._tblErrorMessages[error]..")/r/n",true);
end
Folder.Delete(strRuntimeSupportFolder);
error=Application.GetLastError();
iferror~=0then
SetupData.WriteToLogFile("錯誤/tdotnet2_0模塊:無法刪除臨時文件夾(".._tblErrorMessages[error]..")/r/n",true);
end
end
--是否顯示對話框來詢問用戶是否安裝模塊。
if(bShowUserPrompt)then
localnDialogResult=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”來運行安裝
localnResult=File.Run(strFileToRun,"/R:N","",SW_SHOWNORMAL,true);
if(nResult==3010)then
--VB安裝指明它需要重啟才能完成
--設置SetupFactory的重啟變量,以便在安裝結束時重啟
_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
>
==========================================================================
制作安裝程序,無非是復制文件、注冊控件、注冊服務、修改設置項(注冊表、配置文件)等等。通過一些專門的安裝制作軟件不難做出一個專業的安裝程序。
.net下的WinForm程序,制作安裝包需要做些什么呢?
典型情況下可能需要做如下事情:
1、判斷客戶機是否安裝了.net framework
2、復制程序文件
3、將某些控件加入到全局應用程序緩存(GAC),比如第三方的控件或是自己定義的具有強名稱的控件
4、安裝時的默認設置項,比如程序的配置文件、或修改注冊表等
5、創建快捷方式、軟件的卸載
制作安裝程序的工具比較多,常見的比如InstallShield、Wise Install、以及VS本身自帶安裝程序制作功能,前2個都是專業級的安裝制作工具,所以安裝文件也是巨大。這里我們推薦一款制作安裝程序的軟件Setup factory7.0,使用這個軟件能夠輕松的制作出一個專業的安裝程序,它內置一種跟VBS類似的腳本語言,通過編寫action腳本,能夠實現比較強大的一些,比如從網上下載一些需要的安裝文件。
對于Setup factory7.0的一般性使用這里就不詳細介紹了,自己稍微摸索一下就知道了。我只介紹一下關于如何判斷是否安裝了.net framework及自動下載框架的安裝文件并安裝、如何修改注冊表項、自定義安裝界面等。
1、如何判斷是否安裝了.net framework
這里是判斷注冊表中是否存在框架的注冊項。需要在Setup factory中的工程-操作的OnStartup事件中寫如下代碼:
--
判斷是否安裝了.net框架
hasInstalled
=
Registry.DoesKeyExist(HKEY_LOCAL_MACHINE,
"
Software/Microsoft/.NETFramework
"
);
if
hasInstalled
==
false
then
result
=
Dialog.Message(
"
安裝提示
"
,
"
運行本軟件需要安裝.Net框架1.1版,是否從網絡中下載并安裝?
"
,MB_YESNO,MB_ICONQUESTION,MB_DEFBUTTON1)
if
result
==
IDYES
then
isExists
=
HTTP.TestConnection(
"
http://www.zhangyongjun.com/fdown/uploadfile/dotnetfx.exe
"
,
90
,
80
);
if
isExists
==
true
then
--
ShowtheStatusDlg
StatusDlg.Show(MB_ICONINFORMATION,
false
);
StatusDlg.ShowCancelButton(
true
,
"
取消
"
);
--
Set
statusdlgtitle
and
message
StatusDlg.SetTitle(
"
下載所需文件...
"
);
--
Set
meterrange(maxrange
=
65534
)
StatusDlg.SetMeterRange(
0
,
100
);
--
Downloadafilefromtheinternet
to
theuser
'
scomputer
--
UsesDownloadCallback()
as
thecallback
function
HTTP.Download(
"
http://www.zhangyongjun.com/fdown/uploadfile/dotnetfx.exe
"
,SessionVar.Expand(
"
%TempFolder%/dotnetfx.exe
"
),MODE_BINARY,
20
,
80
,nil,nil,DownloadCallback);
--
HidetheStatusDlg
StatusDlg.Hide();
Shell.Execute(SessionVar.Expand(
"
%TempFolder%/dotnetfx.exe
"
),
"
open
"
,
""
,
""
,SW_SHOWNORMAL)
else
Dialog.Message(
"
錯誤提示
"
,
"
下載文件失敗,可能服務器已停止服務。請從Microsoft網站上下載.NetFramework1.1。
"
,MB_ICONEXCLAMATION);
Application.Exit(
0
);
end
else
Application.Exit(
0
);
end
end
--
Callback
function
for
HTTP.Download
function
DownloadCallback(nDownloaded,nTotal,TransferRate,SecondLeft,SecondsLeftFormat,Message)
--
Converttotal
and
downloadedbytesintoformattedstrings
sDownloaded
=
String
.GetFormattedSize(nDownloaded,FMTSIZE_AUTOMATIC,
true
);
sTotal
=
String
.GetFormattedSize(nTotal,FMTSIZE_AUTOMATIC,
true
);
--
Output
time
left
,formatted.
StatusDlg.SetMessage(
"
正在下載文件...剩余時間:
"
..SecondsLeftFormat);
--
Outputformattedsizes
to
userthroughstatusdlgstatustext
StatusDlg.SetStatusText(
"
已下載:
"
..sDownloaded..
"
/
"
..sTotal);
--
Set
meterposition(fractiondownloaded
*
maxmeterrange)
StatusDlg.SetMeterPos((nDownloaded
/
nTotal)
*
100
);
end
2、操作注冊表
在定制安裝界面中,可以添加一個界面,選擇界面類型,并且能夠自定義界面上的操作事件,比如在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();
Setup Factory 7.0打包.NET FRAMEWORK
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元