Setup Factory 7.0打包.NET FRAMEWORK
系統(tǒng)
2253 0
本文介紹一個工具:Setup Factory。在7.0版本中,Setup Factory的默認(rèn)從屬資源中僅支持VB5.0及VB6.0,想要在生成的安裝程序中自動完成.NET FRAMEWORK的安裝,從網(wǎng)上查了一下,須要按以下步驟做幾件事:
首先找到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內(nèi)容如下:
<
DependencyTemplate
>
<
Dependency
>
<
Name
>
Microsoft.NETFramework2.0
</
Name
>
<
RuntimeTempFolder
>
dotnet2_0
</
RuntimeTempFolder
>
<
RevisionDate
>
Friday,March30,2007
</
RevisionDate
>
<
Description
>
安裝Microsoft.NETFramework2.0應(yīng)用程序所需的運(yùn)行時文件。
</
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=[[安裝程序檢測到你的系統(tǒng)沒有安裝Microsoft.NETFramework2.0或者版本過舊。請點(diǎn)擊“確定”進(jìn)行安裝,點(diǎn)擊“取消”中止安裝。]];
localstrDialogTitle="必需的技術(shù)文件";
localbShowUserPrompt=true;--設(shè)置為true來詢問用戶是否安裝模塊
localbRunInstallFile=true;--設(shè)置默認(rèn)選擇(是否默認(rèn)運(yùn)行安裝)
localstrRuntimeSupportFolder=SessionVar.Expand("%TempLaunchFolder%//dotnet2_0");
localstrFileToRun=strRuntimeSupportFolder.."http://dotnetfx.exe";
-----------------------------------------------------------------------------------------
--安裝已啟動。
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:安裝腳本已啟動。/r/n",true);
--刪除臨時文件和運(yùn)行時支持文件夾(同時進(jìn)行錯誤檢查)
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),準(zhǔn)備安裝。/r/n",true);
else
--用戶不安裝模塊。
bRunInstallFile=false;
--用戶回答否
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:用戶不安裝模塊。/r/n",true);
end
end
--檢查用戶是否要安裝運(yùn)行時。
if(bRunInstallFile)then
--開始!
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:正在運(yùn)行dotnet2_0安裝程序。/r/n",true);
--“/R:N”命令行參數(shù)告訴VB安裝程序若需要的話不要顯示重啟屏幕。
--我們將檢測整個安裝進(jìn)程返回代碼,若需要的話,還設(shè)置內(nèi)部_NeedsReboot變量。
--【注意】在靜默方式下,你不能添加命令行參數(shù)“/Q”來運(yùn)行安裝
localnResult=File.Run(strFileToRun,"/R:N","",SW_SHOWNORMAL,true);
if(nResult==3010)then
--VB安裝指明它需要重啟才能完成
--設(shè)置SetupFactory的重啟變量,以便在安裝結(jié)束時重啟
_NeedsReboot=true;
--需要重啟
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:dotnet2_0安裝程序已告知它需要重啟。/r/n",true);
end
--刪除運(yùn)行時安裝程序文件,并刪除臨時文件夾
PerformCleanUp();
--全部完成!
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:dotnet2_0運(yùn)行時安裝完畢。/r/n",true);
else
--用戶不想安裝運(yùn)行時,那么刪除運(yùn)行時安裝程序文件,
--并刪除臨時文件夾,然后退出安裝程序。
PerformCleanUp();
--全部完成!
SetupData.WriteToLogFile("成功/tdotnet2_0模塊:dotnet2_0運(yùn)行時未安裝。/r/n",true);
Application.Exit();
end
</
InstallScript
>
<
SupportFiles
>
<
File
>
#SUFDIR#/Dependencies/dotnet2_0/dotnetfx.exe
</
File
>
</
SupportFiles
>
</
Dependency
>
</
DependencyTemplate
>
==========================================================================
制作安裝程序,無非是復(fù)制文件、注冊控件、注冊服務(wù)、修改設(shè)置項(xiàng)(注冊表、配置文件)等等。通過一些專門的安裝制作軟件不難做出一個專業(yè)的安裝程序。
.net下的WinForm程序,制作安裝包需要做些什么呢?
典型情況下可能需要做如下事情:
1、判斷客戶機(jī)是否安裝了.net framework
2、復(fù)制程序文件
3、將某些控件加入到全局應(yīng)用程序緩存(GAC),比如第三方的控件或是自己定義的具有強(qiáng)名稱的控件
4、安裝時的默認(rèn)設(shè)置項(xiàng),比如程序的配置文件、或修改注冊表等
5、創(chuàng)建快捷方式、軟件的卸載
制作安裝程序的工具比較多,常見的比如InstallShield、Wise Install、以及VS本身自帶安裝程序制作功能,前2個都是專業(yè)級的安裝制作工具,所以安裝文件也是巨大。這里我們推薦一款制作安裝程序的軟件Setup factory7.0,使用這個軟件能夠輕松的制作出一個專業(yè)的安裝程序,它內(nèi)置一種跟VBS類似的腳本語言,通過編寫action腳本,能夠?qū)崿F(xiàn)比較強(qiáng)大的一些,比如從網(wǎng)上下載一些需要的安裝文件。
對于Setup factory7.0的一般性使用這里就不詳細(xì)介紹了,自己稍微摸索一下就知道了。我只介紹一下關(guān)于如何判斷是否安裝了.net framework及自動下載框架的安裝文件并安裝、如何修改注冊表項(xiàng)、自定義安裝界面等。
1、如何判斷是否安裝了.net framework
這里是判斷注冊表中是否存在框架的注冊項(xiàng)。需要在Setup factory中的工程-操作的OnStartup事件中寫如下代碼:
--
判斷是否安裝了.net框架
hasInstalled
=
Registry.DoesKeyExist(HKEY_LOCAL_MACHINE,
"
Software/Microsoft/.NETFramework
"
);
if
hasInstalled
==
false
then
result
=
Dialog.Message(
"
安裝提示
"
,
"
運(yùn)行本軟件需要安裝.Net框架1.1版,是否從網(wǎng)絡(luò)中下載并安裝?
"
,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(
"
錯誤提示
"
,
"
下載文件失敗,可能服務(wù)器已停止服務(wù)。請從Microsoft網(wǎng)站上下載.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編寫腳本以實(shí)現(xiàn)特定的功能,下面的代碼是實(shí)現(xiàn)在自定義的配置設(shè)置界面中用戶填寫完配置信息后,點(diǎn)“下一步”時,將填寫的信息寫入到注冊表,其中CTRL_EDIT_01等為編輯控件(這里是文本框)的ID。
--
這些操作在點(diǎn)擊“下一步”按鈕時執(zhí)行。
--
提示:你可以在這里添加驗(yàn)證用戶輸入信息的操作
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);
--
進(jìn)入下一個屏幕
Screen.Next();
Setup Factory 7.0打包.NET FRAMEWORK
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元