上一篇說道了InstallShield快速建立一個打包程序,現在說說InstallShield裏面的installscript腳本。該文屬於個人理解,參考一些相關文章。
相關資料下載地址:http://download.csdn.net/detail/iamdale11/8104971
該資料中包括InstallShield內部庫函數以及一篇對dialog的理解
首先,在上一篇的基礎上,點擊installation Designer.
點擊下面的InstallScript。
先點擊Setup.rul,然後如下圖選擇Before Move Data和OnFirstUIBefore.會在setup.rul文件中顯示出上一篇文章中快速打包的程序源代碼。
1、在安裝過程中,需要先輸入序列號,在自己定義流程中添加如下代碼:
Dlg_SdRegisterUserEx://標籤
szMsg = "";//信息字段
szTitle = "";//標題
szSerial = ""; //序列號
Disable (BACKBUTTON);//隱藏返回按鈕
nResult = SdRegisterUserEx(szTitle,szMsg, szName,szCompany, szSerial );//調用庫函數顯示相應的dialog
//判斷序列號是否正確
if ( szSerial != '1111') then
MessageBox("警告:輸入序列號錯誤,請確認後重輸!",SEVERE);
goto Dlg_SdRegisterUserEx;
endif;
if (nResult = BACK) goto Dlg_SdWelcome;
2、在安裝過程中,需要對安裝程序進行相應的環境檢測,在自己需要檢測的地方添加如下代碼:
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);//獲取註冊表中的HKEY_LOCAL_MACHINE值。
if (RegDBKeyExist ("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0") < 0) then//判斷相應的環境是否存在,這裏是。NET 4.0
MessageBox("未安裝相應運行環境,正在進行安裝",WARNING);
// LaunchAppAndWait (SRCDISK^"1233456789.exe","", LAAW_OPTION_WAIT); //調用相應盤中的相關程序進行安裝。
goto Dlg_SdLicense2;
else
MessageBox("已安裝相應的環境",WARNING);
endif;
3、自定義dialog
如下圖點擊dialog,然後在all Dialog上右鍵點擊new dialog。創建自定義的dialog。
然後在Files中右鍵創建新的.rul文件對相應的dialog進行文件創建。
如selectdlg.rul文件中代碼如下:
//宏定義相關量,注意,爲了取得dialog窗體上的相關特徵,需要將相關特徵的control identifier中的值取出
#define DLG_SELECTDLG "SelectDlg"
#define GENGXIN 1322
#define ANZHUANG 1323
#define NEXTBTN 1
#define BACKBTN 12
prototype SelectDlg(BYREF STRING,BYREF STRING); //定義一個方法
function SelectDlg( szTitle,szMsg)
//定義相關變量
number nId, nResult,szGGZZ,szTest;
HWND hwndDlg;
BOOL bDone;
string szGZ1,szGZ2,szTe;
begin
// Specify a name to identify the custom dialog in this installation.
// ensure general initialization is complete
if( !bSdInit ) then
SdInit();
endif;
//聲明一個窗體
nResult = EzDefineDialog(DLG_SELECTDLG, ISUSER, "SelectDlg", 0 );
//MessageBox(szGZ,WARNING);
// Initialize the indicator used to control the while loop.
bDone = FALSE;
// Loop until done.
while (!bDone)
// Display the dialog and return the next dialog event.
nId = WaitOnDialog(DLG_SELECTDLG); //顯示一個窗體
// Respond to the event.
switch(nId)
case DLG_INIT: //窗體初始化相關操作
CtrlSetState(DLG_SELECTDLG, ANZHUANG, BUTTON_CHECKED);
// No initialization is required for this example.
case NEXTBTN://下一步按鈕操作
// getCtrlText();
if(CtrlGetState(DLG_SELECTDLG, GENGXIN) = BUTTON_CHECKED) then//判斷radio按鈕是否選中
nId=NEXT;
endif;
if(CtrlGetState(DLG_SELECTDLG, GENGXIN) = BUTTON_CHECKED) then
nId=CUSTOM;
endif;
bDone = TRUE;
case BACK://返回按鈕
nId = BACK;
bDone = TRUE;
case DLG_ERR:
SdError( -1, "Errrrrrrr" );
nId = -1;
bDone = TRUE;
case DLG_CLOSE:
SdCloseDlg( hwndDlg, nId, bDone );
default:
// check standard handling
if(SdIsStdButton( nId ) && SdDoStdButton( nId )) then
bDone = TRUE;
endif;
endswitch;
endwhile;
// Cleanup Dialog
EndDialog( DLG_SELECTDLG );//結束窗體
ReleaseDialog( DLG_SELECTDLG );//釋放窗體
SdUnInit();
// record data produced by this dialog
if( MODE = RECORDMODE ) then
endif;
return nId;
end;
4.文件複製操作
VarSave (SRCTARGETDIR); //保存系統變量值
SRCDIR =Strjq;//Strjq是路徑字符串,裏面保存的是相應路徑
TARGETDIR=svDir; //svDir是路徑字符串,裏面保存的是相應路徑
nResult=CopyFile( "*.*", "*.*"); //複製操作,具體可參看庫函數介紹
VarRestore (SRCTARGETDIR); // 恢復缺省的源文件夾和目標文件夾路徑
5.按鈕驗證函數,具體可參看資料中的自定義dialog淺談。
function CheckInputValid(hwndDlg, bAllowNotSet)
STRING szInputAdd;
begin
if(bAllowNotSet) then
_WinSubEnableControl(hwndDlg, SD_PBUT_CONTINUE, 1);
return 1;
endif;
CtrlGetText(DLG_GXDLG, SVDIR, szInputAdd);
if(StrLength(szInputAdd) = 0) then
_WinSubEnableControl(hwndDlg, SD_PBUT_CONTINUE, 0);
return 0;
endif;
_WinSubEnableControl(hwndDlg, SD_PBUT_CONTINUE, 1);
return 1;
end;
我的感悟大致就是這些,請大家多多指出錯誤,相互討論。