昨天学了一些基本语法《InstallShield脚本语言的初识》,只是试水,今天准备写个例子,看看具体脚本的写法。
ok,记录完成。这就是在没有脚本控制下默认生成的安装程序。
从两个下拉框中可以看到这些函数,无论在脚本中如何重写这些函数,它们的执行顺序总是固定的,就按照在下拉框中排列的顺序,从上到下执行。
以下实例都是我在网上搜刮的,大多都是pdf中的看到然后我自己敲出来运行测试的,来源不可考证,就不备注了,还请原作者见谅。
function OnBegin()
string szMsg;
begin
/*
* <操作系统的识别>
* 相关变量 SYSINFO:存放本机的系统变量
* 相关函数 AskYesNo:弹出消息窗口,用户通过按是或非来回答该窗口显示的问题
*/
if(!SYSINFO.bIntel)then
szMsg = "提示:该软件只能运行在Intel系列的处理器上!\n\n安装程序将终止";
MessageBox(szMsg,SEVERE);
abort;
endif;
if(SYSINFO.WIN9X.bWinMe ||
SYSINFO.WINNT.bWinNT ||
SYSINFO.WINNT.bWin2000)then
szMsg = "提示:该软件只能运行在WIN9X系列上才能确保程序的正常工作!\n\n是否继续安装?";
if(!AskYesNo(szMsg,NO))then
abort;
endif;
endif;
end;
点击“是”,则正常安装;点击“否”,会退出安装。abort命令在《InstallShield脚本语言的初识》中有讲到。
function OnBegin()
string szMsg,svResult;
number nvFreeMem;
begin
/*
* <操作系统的识别>
* 相关变量 SYSINFO 存放本机的系统变量
* 相关函数 AskYesNo 弹出消息窗口,用户通过按是或非来回答该窗口显示的问题
*/
if(!SYSINFO.bIntel)then
szMsg = "提示:该软件只能运行在Intel系列的处理器上!\n\n安装程序将终止";
MessageBox(szMsg,SEVERE);
abort;
endif;
if(SYSINFO.WIN9X.bWinMe ||
SYSINFO.WINNT.bWinNT ||
SYSINFO.WINNT.bWin2000)then
szMsg = "提示:该软件只能运行在WIN9X系列上才能确保程序的正常工作!\n\n是否继续安装?";
if(!AskYesNo(szMsg,NO))then
abort;
endif;
endif;
/*
* <内存容量的检测>
* 相关函数:GetSystemInfo() 返回目标系统的各种信息,
* 如CPU类型,磁盘容量,当前日期,当前操作系统,内存容量等
*/
if(GetSystemInfo(EXTENDEDMEMORY,nvFreeMem,svResult)<0)then
MessageBox("内存检测失败,安装程序将终止!",SEVERE);
abort;
endif;
if(nvFreeMem<16384)then
szMsg = "该软件只能安装在16M以上内存的机器中。\n很遗憾,本机器可用内存不足16M!\n\n安装程序将终止!";
MessageBox(szMsg,SEVERE);
abort;
endif;
end;
客户信息的缺省值已经被填写,而这一段内容则是来自一个很重要的事件,OnFirstUIBefore。
打开OnFirstUIBefore,可以看到它和OnBegin不同,里面已经内置有很多代码。想知道这些代码都是干什么用的?一个一个试试看呗~
我先试了一下注释掉它们,发现安装程序并没有什么变化。然后我改动了它们的值。
//只改了这两个
szName = "seven";
szCompany = "mosia";
顺便一提,我还改了bLicenseAccepted的值为TRUE,发现许可认证的选择默认会选择“我接受”,不禁让人想起来之前支付宝账单搞事情……总之这一项还是永远保持FALSE吧。
Dlg_SdWelcome:
szTitle = "SdWelcome"; //我改动的地方
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdWelcome)
nResult = SdWelcome( szTitle, szMsg );
//}}IS_SCRIPT_TAG(Dlg_SdWelcome)
if (nResult = BACK) goto Dlg_Start;
之后来看看每个分支的代码。做一些改动。
function OnFirstUIBefore()
number nResult, nLevel, nSize, nSetupType;
string szTitle, szMsg, szOpt1, szOpt2, szLicenseFile;
string szName, szCompany, szTargetPath, szDir, szFeatures;
BOOL bLicenseAccepted;
begin
// Added in InstallShield 15 - Show an appropriate error message if
// -removeonly is specified and the product is not installed.
if( REMOVEONLY ) then
Disable( DIALOGCACHE );
szMsg = SdLoadString( IDS_IFX_ERROR_PRODUCT_NOT_INSTALLED_UNINST );
SdSubstituteProductInfo( szMsg );
MessageBox( szMsg, SEVERE );
abort;
endif;
nSetupType = COMPLETE;
szDir = TARGETDIR;
szName = "seven";
szCompany = "mosia";
bLicenseAccepted = FALSE;
// Beginning of UI Sequence
Dlg_Start:
nResult = 0;
Dlg_SdWelcome:
szTitle = "SdWelcome";
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdWelcome)
nResult = SdWelcome( szTitle, szMsg );
//}}IS_SCRIPT_TAG(Dlg_SdWelcome)
if (nResult = BACK) goto Dlg_Start;
Dlg_SdLicense2:
szTitle = "SdLicense2";
szOpt1 = "";
szOpt2 = "";
//{{IS_SCRIPT_TAG(License_File_Path)
szLicenseFile = SUPPORTDIR ^ "License.rtf";
//}}IS_SCRIPT_TAG(License_File_Path)
//{{IS_SCRIPT_TAG(Dlg_SdLicense2)
nResult = SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, TRUE );
//}}IS_SCRIPT_TAG(Dlg_SdLicense2)
if (nResult = BACK) then
goto Dlg_SdWelcome;
else
bLicenseAccepted = TRUE;
endif;
// 我的改动:注释了Dlg_SdRegisterUser分支
/*
Dlg_SdRegisterUser:
szMsg = "";
szTitle = "SdRegisterUser";
//{{IS_SCRIPT_TAG(Dlg_SdRegisterUser)
nResult = SdRegisterUser( szTitle, szMsg, szName, szCompany );
//}}IS_SCRIPT_TAG(Dlg_SdRegisterUser)
if (nResult = BACK) goto Dlg_SdLicense2;
*/
Dlg_SetupType2:
szTitle = "SetupType2";
szMsg = "";
nResult = CUSTOM;
//{{IS_SCRIPT_TAG(Dlg_SetupType2)
nResult = SetupType2( szTitle, szMsg, "", nSetupType, 0 );
//}}IS_SCRIPT_TAG(Dlg_SetupType2)
if (nResult = BACK) then
goto Dlg_SdLicense2; // 我的改动:原本是goto到Dlg_SdRegisterUser
else
nSetupType = nResult;
if (nSetupType != CUSTOM) then
szTargetPath = TARGETDIR;
nSize = 0;
FeatureCompareSizeRequired( MEDIA, szTargetPath, nSize );
if (nSize != 0) then
MessageBox( szSdStr_NotEnoughSpace, WARNING );
goto Dlg_SetupType2;
endif;
endif;
endif;
Dlg_SdAskDestPath2:
if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType2;
szTitle = "SdAskDestPath2";
szMsg = "";
if (nSetupType = CUSTOM) then
//{{IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
nResult = SdAskDestPath2( szTitle, szMsg, szDir );
//}}IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
TARGETDIR = szDir;
endif;
if (nResult = BACK) goto Dlg_SetupType2;
Dlg_SdFeatureTree:
if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SdAskDestPath2;
szTitle = "SdFeatureTree";
szMsg = "";
szFeatures = "";
nLevel = 2;
if (nSetupType = CUSTOM) then
//{{IS_SCRIPT_TAG(Dlg_SdFeatureTree)
nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, szFeatures, nLevel );
//}}IS_SCRIPT_TAG(Dlg_SdFeatureTree)
if (nResult = BACK) goto Dlg_SdAskDestPath2;
endif;
Dlg_SQLServer:
nResult = OnSQLServerInitialize( nResult );
if( nResult = BACK ) goto Dlg_SdFeatureTree;
Dlg_ObjDialogs:
nResult = ShowObjWizardPages( nResult );
if (nResult = BACK) goto Dlg_SQLServer;
Dlg_SdStartCopy2:
szTitle = "SdStartCopy2";
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdStartCopy2)
nResult = SdStartCopy2( szTitle, szMsg );
//}}IS_SCRIPT_TAG(Dlg_SdStartCopy2)
if (nResult = BACK) goto Dlg_ObjDialogs;
// Added in 11.0 - Set appropriate StatusEx static text.
SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) );
return 0;
end;
function OnFirstUIBefore()
number nResult, nLevel, nSize, nSetupType;
string szTitle, szMsg, szOpt1, szOpt2, szLicenseFile;
string szName, szCompany, szTargetPath, szDir, szFeatures;
BOOL bLicenseAccepted;
begin
// Added in InstallShield 15 - Show an appropriate error message if
// -removeonly is specified and the product is not installed.
if( REMOVEONLY ) then
Disable( DIALOGCACHE );
szMsg = SdLoadString( IDS_IFX_ERROR_PRODUCT_NOT_INSTALLED_UNINST );
SdSubstituteProductInfo( szMsg );
MessageBox( szMsg, SEVERE );
abort;
endif;
szDir = TARGETDIR;
bLicenseAccepted = FALSE;
// Beginning of UI Sequence
Dlg_Start:
nResult = 0;
Dlg_SdLicense2:
szTitle = "SdLicense2";
szOpt1 = "";
szOpt2 = "";
//{{IS_SCRIPT_TAG(License_File_Path)
szLicenseFile = SUPPORTDIR ^ "License.rtf";
//}}IS_SCRIPT_TAG(License_File_Path)
//{{IS_SCRIPT_TAG(Dlg_SdLicense2)
nResult = SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, TRUE );
//}}IS_SCRIPT_TAG(Dlg_SdLicense2)
if (nResult = BACK) then
goto Dlg_Start;
else
bLicenseAccepted = TRUE;
endif;
Dlg_SdWelcome:
szTitle = "SdWelcome";
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdWelcome)
nResult = SdWelcome( szTitle, szMsg );
//}}IS_SCRIPT_TAG(Dlg_SdWelcome)
if (nResult = BACK) goto Dlg_SdLicense2;
Dlg_SdAskDestPath2:
if (nResult = BACK) goto Dlg_SdWelcome;
szTitle = "SdAskDestPath2";
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
nResult = SdAskDestPath2( szTitle, szMsg, szDir );
//}}IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
TARGETDIR = szDir;
if (nResult = BACK) goto Dlg_SdWelcome;
// Added in 11.0 - Set appropriate StatusEx static text.
SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) );
return 0;
end;
今天主要是优化了下安装前导航,比较皮毛。明天继续研究更深层一些的东西,比如注册表写入。