#include "ifx.h" //不能移動(dòng)
//////////////////////////////////////////////////////////////////////////////
// 用installshield 進(jìn)行 asp 軟件的打包和自動(dòng)安裝
// 原創(chuàng)作者: 賈俊 (jaron)
// 網(wǎng)址: http://jiangdu.net
// 郵件: jaron@jdinfo.net
// 首次發(fā)表于網(wǎng)易,chinaasp,asphouse
//////////////////////////////////////////////////////////////////////////////
// 功能:
// 1.文件復(fù)制
// 2.可選自動(dòng)設(shè)置獨(dú)立站點(diǎn)運(yùn)行(設(shè)置iis)
// 3.可選自動(dòng)設(shè)置虛擬站點(diǎn)運(yùn)行(設(shè)置iis)
// 4.設(shè)置目錄可讀,可寫(xiě)及可運(yùn)行腳本
// 5.自動(dòng)創(chuàng)建odbc
// 6.自動(dòng)創(chuàng)建或附加mdf格式的sql數(shù)據(jù)庫(kù) 并優(yōu)化
// 7.自動(dòng)安裝 scriptencode 解碼程序
// 本文僅列出了 installshield 的 script 部分,還有兩個(gè) vbs 文件及其他設(shè)置
// 測(cè)試過(guò)程中有任何問(wèn)題,請(qǐng)來(lái) http://jiangdu.net/bbs 編程空間版 討論
//////////////////////////////////////////////////////////////////////////////
prototype createdatabase(string,string,string);
prototype createwebsite(string,string); // 創(chuàng)建 iis 站點(diǎn)
prototype createvirtualdir(string); // 創(chuàng)建虛擬目錄
//////////////////////////////////////////////////////////////////////////////
//
// 函數(shù): onfirstuibefore
//
// 事件: firstuibefore event is sent when installation is run for the first
// time on given machine. in the handler installation usually displays
// ui allowing end user to specify installation parameters. after this
// function returns, componenttransferdata is called to perform file
// transfer.
//
///////////////////////////////////////////////////////////////////////////////
function onfirstuibefore()
number nresult,nsetuptype,nopt,svedit1,svedit2;
string sztitle, szmsg,szbmppath;
string szlicensefile, szquestion;
string szserverip,szserverport,szserveripdefault,szserverportdefault;
string szsqlsvr,szsqlusr,szsqlpwd,svsqlsvr,svsqlusr,svsqlpwd;
string svname, svcompany, svserial;
string szfile,sztargetpath,szdir,szfolder;
string szcomponents, sztargetdir;
string szfield1,szfield2;
string szdefault,svresult;
object piisobj;
list list,liststartcopy;
number nlevel,nvsize;
begin
szbmppath="c:"^"temp"^"left.bmp";
dialogsetinfo (dlg_info_altimage, szbmppath, true); // 設(shè)置左邊的圖片
//to do: if you want to enable background, window title, and caption bar title
//settitle( @title_main, 24, white );
//settitle( @title_captionbar, 0, backgroundcaption );
//enable( fullwindowmode );
//enable( background );
//setcolor(background,rgb (0, 128, 128));
//默認(rèn)值設(shè)定
targetdir = "c:"^"inetpub"^"jaronsoft"^@folder_name;
szdir = targetdir;
shell_object_folder = @folder_name;
svname = "試用版用戶(hù)";
svcompany = "jdinfo network";
svserial = "111-1111111";
dlg_start:
// beginning of dialogs label
dlg_sdwelcome: //歡迎 對(duì)話(huà)框
sztitle = "歡迎進(jìn)入";
szmsg = "";
nresult = sdwelcome( sztitle, szmsg );
if (nresult = back) goto dlg_start;
dlg_sdlicense://軟件許可協(xié)議 對(duì)話(huà)框
szlicensefile = supportdir ^ "license.txt";
sztitle = "許可協(xié)議";
szmsg = "";
szquestion = "";
nresult = sdlicense( sztitle, szmsg, szquestion, szlicensefile );
if (nresult = back) goto dlg_sdwelcome;
dlg_sdshowinfolist://readme文件 對(duì)話(huà)框
szfile = supportdir ^ "infolist.txt";
list = listcreate( stringlist );
listreadfromfile( list, szfile );
sztitle = "readme";
szmsg = "";
nresult = sdshowinfolist( sztitle, szmsg, list );
listdestroy( list );
if (nresult = back) goto dlg_sdlicense;
dlg_sdregisteruserex://用戶(hù)信息 對(duì)話(huà)框
szmsg = "";
sztitle = "用戶(hù)信息";
nresult = sdregisteruserex( sztitle, szmsg, svname, svcompany, svserial );
if (nresult = back) goto dlg_sdshowinfolist;
//檢查序列號(hào)
//if (chk_serial(svcompany, svserial)<0) then
//goto dlg_sdregisteruserex;
//endif;
//檢查序列號(hào)完畢
dlg_sdaskdestpath://安裝位置 對(duì)話(huà)框
sztitle = "檢查序列號(hào)";
szmsg = "";
nresult = sdaskdestpath( sztitle, szmsg, szdir, 0 );
targetdir = szdir;
if (nresult = back) goto dlg_sdregisteruserex;
dlg_setuptype: //安裝類(lèi)型 對(duì)話(huà)框
nsetuptype = typical;
sztitle = "安裝類(lèi)型";
szmsg = "請(qǐng)選擇您需要按哪種方式安裝";
nresult = setuptype ( sztitle , szmsg , "" , nsetuptype , 0 );
if (nresult = back) then
goto dlg_sdaskdestpath;
else
nsetuptype = nresult;
if (nsetuptype != custom) then
sztargetpath = targetdir;
nvsize = 0;
componentcomparesizerequired(media,sztargetpath,nvsize);
if (nvsize != 0) then
messagebox( szsdstr_notenoughspace, warning );
goto dlg_setuptype;
endif;
endif;
endif;
dlg_sdcomponenttree: //對(duì)話(huà)框
if ((nresult = back) && (nsetuptype != custom)) goto dlg_setuptype;
sztitle = "對(duì)話(huà)框";
szmsg = "";
sztargetdir = targetdir;
szcomponents = "";
nlevel = 2;
if (nsetuptype = custom) then
nresult = sdcomponenttree(sztitle, szmsg, sztargetdir, szcomponents, nlevel);
if (nresult = back) goto dlg_setuptype;
endif;
dlg_sdselectfolder://對(duì)話(huà)框
szfolder = shell_object_folder;
sztitle = "文件夾";
szmsg = "";
nresult = sdselectfolder( sztitle, szmsg, szfolder );
shell_object_folder = szfolder;
if (nresult = back) goto dlg_sdcomponenttree;
dlg_selmode ://設(shè)置數(shù)據(jù)庫(kù)服務(wù)器 對(duì)話(huà)框
sztitle = "設(shè)置"+@product_name+"的運(yùn)行模式";
szmsg = "請(qǐng)選擇軟件運(yùn)行的方式,極力推薦使用獨(dú)立站點(diǎn)方式運(yùn)行";
szfield1="獨(dú)立站點(diǎn)方式運(yùn)行(自動(dòng)創(chuàng)建新站點(diǎn))";
szfield2="虛擬目錄方式運(yùn)行(自動(dòng)創(chuàng)建虛擬目錄)";
svedit1=true;
svedit2=false;
setdialogtitle(dlg_ask_text,sztitle);
//dialogsetinfo ( dlg_info_checkselection, "", 1);
nopt = exclusive ;
nresult = askoptions (nopt,szmsg,szfield1,svedit1,szfield2,svedit2);
if (nresult = back) goto dlg_sdselectfolder;
if (svedit1=false) goto dlg_sdstartcopy;
dlg_asktext ://設(shè)置數(shù)據(jù)庫(kù)服務(wù)器 對(duì)話(huà)框
sztitle = "設(shè)置iis信息服務(wù)及數(shù)據(jù)庫(kù)服務(wù)器";
szmsg = "現(xiàn)在開(kāi)始設(shè)置iis系統(tǒng)";
szquestion=" 請(qǐng)輸入本服務(wù)器的主機(jī)名或ip地址,安裝程序?qū)凑漳峁┑馁Y料設(shè)置iis信息服務(wù)。如果您沒(méi)有填寫(xiě),安裝程序?qū)⒆詣?dòng)跳過(guò)站點(diǎn)的創(chuàng)建!";
szserverip="地址:";
szserverport="端口:";
szserveripdefault="192.168.0.1";
szserverportdefault="80";
setdialogtitle(dlg_ask_text,sztitle);
nresult=sdshowdlgedit2 (sztitle, szquestion,szserverip,szserverport,szserveripdefault,szserverportdefault);
if (nresult = back) goto dlg_selmode;
dlg_asksql ://設(shè)置數(shù)據(jù)庫(kù)服務(wù)器 對(duì)話(huà)框
sztitle = "設(shè)置數(shù)據(jù)庫(kù)";
szmsg = "現(xiàn)在開(kāi)始設(shè)置microsoft sql server數(shù)據(jù)庫(kù)系統(tǒng)";
szquestion=" 請(qǐng)輸入sql server數(shù)據(jù)庫(kù)服務(wù)器的用戶(hù)名和密碼,安裝程序?qū)凑漳喜教峁┑膇p地址和下面的用戶(hù)名和密碼創(chuàng)建和優(yōu)化數(shù)據(jù)庫(kù)系統(tǒng)。如果您提供的用戶(hù)名和密碼是錯(cuò)誤的,安裝程序?qū)⒆詣?dòng)跳過(guò)數(shù)據(jù)的設(shè)置!";
szsqlsvr="主機(jī)名:";
szsqlusr="用戶(hù)名:";
szsqlpwd="密碼:";
svsqlsvr="localhost";
svsqlusr="sa";
szsqlpwd="";
setdialogtitle(dlg_ask_text,sztitle);
nresult=sdshowdlgedit3 (sztitle, szquestion,szsqlsvr,szsqlusr,szsqlpwd,svsqlsvr,svsqlusr,svsqlpwd);
if (nresult = back) goto dlg_selmode;
dlg_sdstartcopy://開(kāi)始復(fù)制文件 對(duì)話(huà)框
sztitle = "開(kāi)始復(fù)制文件";
szmsg = "點(diǎn)擊下一步開(kāi)始復(fù)制文件";
liststartcopy = listcreate( stringlist );
listaddstring(liststartcopy,"用戶(hù)名:"+svname,after);
listaddstring(liststartcopy,"公司名稱(chēng):"+svcompany,after);
listaddstring(liststartcopy,"序列號(hào):"+svserial,after);
listaddstring(liststartcopy,"目標(biāo)目錄:"+szdir,after);
if (svedit1=true) then
listaddstring(liststartcopy,"ip地址:"+szserveripdefault,after);
listaddstring(liststartcopy,"端口號(hào):"+szserverportdefault,after);
endif;
listaddstring(liststartcopy,"請(qǐng)確認(rèn)您填寫(xiě)的信息,按下一步開(kāi)始復(fù)制文件",after);
nresult = sdstartcopy( sztitle, szmsg, liststartcopy );
listdestroy(liststartcopy);
if (nresult = back) goto dlg_asktext;
// setup default status
setstatuswindow(0, "");
enable(statusex);
statusupdate(on, 100);
if (svedit1=true) then
createwebsite(szserveripdefault,szserverportdefault); // 開(kāi)始創(chuàng)建 iis 站點(diǎn)
endif;
if (svedit2=true) then
createvirtualdir("netoa"); // 開(kāi)始創(chuàng)建 iis 站點(diǎn)
endif;
createdatabase(svsqlsvr,svsqlusr,svsqlpwd); // 創(chuàng)建和優(yōu)化數(shù)據(jù)庫(kù)
return 0;
end;
//////////////////////////////////////////////////////////////////////////////
//
// 函數(shù): onfirstuiafter
//
// 事件: firstuiafter event is sent after file transfer, when installation
// is run for the first time on given machine. in this event handler
// installation usually displays ui that will inform end user that
// installation has been completed successfully.
//
///////////////////////////////////////////////////////////////////////////////
function onfirstuiafter()
string sztitle,szmsg1, szmsg2, szoption1, szoption2,szcmdline;
number bopt1, bopt2;
begin
//set_vod_liveaddress();
szcmdline = supportdir ^"sce10chs.exe";
if (launchappandwait(szcmdline, " /q",wait) < 0) then
messagebox ("不能安裝解碼程序,請(qǐng)聯(lián)系供應(yīng)商.",severe);
endif;
disable(statusex);
bopt1 = false;
bopt2 = false;
szmsg1 = sdloadstring(ifx_sdfinish_msg1);
szmsg2 = "請(qǐng)瀏覽本主機(jī)web服務(wù)器上的 "+@product_name+" 虛擬目錄\n\n 例:\n /";
szoption1 = "";
szoption2 = "";
sztitle = @product_name+"安裝完成";
sdfinishex(sztitle,szmsg1,szmsg2,szoption1,szoption2,bopt1,bopt2);
szcmdline = "";
//if (launchapp(programfiles ^"internet explorer"^"iexplore.exe", szcmdline) < 0) then
//messagebox ("不能打開(kāi)瀏覽器.",severe);
//endif;
return 0;
end;
//////////////////////////
// 創(chuàng)建iis站點(diǎn)
//////////////////////////
function createwebsite(szserveripdefault,szserverportdefault)
string szcmdline,szwaittxt;
begin
if ((szserveripdefault = "") || (szserverportdefault = "")) then
messagebox ("您沒(méi)有設(shè)定"+@product_name+"運(yùn)行的服務(wù)器ip地址或端口??!iis信息服務(wù)設(shè)置失??!\n請(qǐng)自行創(chuàng)建iis站點(diǎn),并將主目錄設(shè)為:"+targetdir,severe);
else
szwaittxt=" 正在創(chuàng)建iis和設(shè)置站點(diǎn)....";
sdshowmsg (szwaittxt, true);
delay(2);
szcmdline = supportdir ^"mkw3site.vbs"+" -r "+targetdir+" -i "+szserveripdefault+" -o "+szserverportdefault+" -t "+@product_name;
if (launchappandwait("wscript.exe", szcmdline,wait) < 0) then
messagebox ("不能建立web 虛擬目錄,沒(méi)有找到 wscript.exe 或執(zhí)行腳本錯(cuò)誤.",severe);
endif;
sdshowmsg (szwaittxt, false);
endif;
return 0;
end;
//////////////////////////
// 創(chuàng)建虛擬目錄
//////////////////////////
function createvirtualdir(virtualfolder)
string szcmdline,szwaittxt;
begin
if (virtualfolder = "") then
messagebox ("沒(méi)能讀取到虛擬目錄的名稱(chēng)!請(qǐng)聯(lián)系系統(tǒng)供應(yīng)商!"+targetdir,severe);
else
szwaittxt=" 正在創(chuàng)建"+@product_name+"的虛擬目錄....";
sdshowmsg (szwaittxt, true);
delay(2);
szcmdline = supportdir ^"mkwebdir.vbs "+" -w 1 -v \""+virtualfolder+"\",\""+ targetdir+"\"" ;
if (launchappandwait("wscript.exe", szcmdline,wait) < 0) then
messagebox ("不能建立web 虛擬目錄,沒(méi)有找到 wscript.exe 或執(zhí)行腳本錯(cuò)誤.",severe);
endif;
sdshowmsg (szwaittxt, false);
endif;
return 0;
end;
//////////////////////////
// 創(chuàng)建和優(yōu)化數(shù)據(jù)庫(kù)
//////////////////////////
function createdatabase(svsqlsvr,svsqlusr,svsqlpwd)
string szcmdline,szwaittxt;
begin
szwaittxt=" 正在創(chuàng)建"+@product_name+"所需數(shù)據(jù)庫(kù)....";
sdshowmsg (szwaittxt, true);
delay(2);
szcmdline = "/u "+svsqlusr+" /p "+svsqlpwd+" /s "+svsqlsvr+" /q \"exec sp_attach_db n'oasystem' , n'"+supportdir ^"oasystem_data.mdf'\"";
if (launchappandwait("osql.exe", szcmdline,wait) < 0) then
messagebox ("數(shù)據(jù)庫(kù)創(chuàng)建失??!請(qǐng)確您的系統(tǒng)中已安裝 microsoft sql server 2000.\n如仍無(wú)法解決,請(qǐng)聯(lián)系系統(tǒng)供應(yīng)商!",severe);
endif;
sdshowmsg (szwaittxt, false);
szwaittxt=" 正在優(yōu)化"+@product_name+"系統(tǒng)數(shù)據(jù)庫(kù)....";
sdshowmsg (szwaittxt, true);
delay(2);
szcmdline = "/u "+svsqlusr+" /p "+svsqlpwd+" /s "+svsqlsvr+" /q \"use oasystem ; exec sp_updatestats\"";
if (launchappandwait("osql.exe", szcmdline,wait) < 0) then
messagebox ("數(shù)據(jù)庫(kù)優(yōu)化失?。∧梢栽?sql查詢(xún)分析器中執(zhí)行 \n use oasystem ; exec sp_updatestats \n完成!",severe);
endif;
sdshowmsg (szwaittxt, false);
return 0;
end;
該文章在 2010/7/4 23:51:07 編輯過(guò)