1. 程式人生 > >inno setup製作安裝包的經驗

inno setup製作安裝包的經驗

   利用inno setup製作安裝包,inno setup下面編寫的指令碼語言用的pascal語言,不過編寫安裝包也只是需要用到簡單的pascal語言語法,然後瞭解一下一些inno setup安裝過程預設執行的函式,其實這些函式右鍵的安裝事件裡面都是有的,大家將需要用到的自己瞭解瞭解就行。

  指令碼語言執行的都是一些Command命令,這些如果不懂上網一搜一大堆,inno setup可以自己定製自己想要實現的介面,相對於vs裡面製作安裝的程式還比較靈活的,inno setup裡面有一些固定的程式碼格式,例如icons、files等等知道就可以了,廢話不多說直接上我這次安裝包的程式,程式後面我都帶上了註釋,希望各位都能看的懂。

  ; 指令碼用 Inno Setup 指令碼嚮導 生成。
; 查閱文件獲取建立 INNO SETUP 指令碼檔案的詳細資料!

#define SERIES              "***"
#define MyAppId             "{736AE8B4-49C3-4142-A4CB-13CC80D43B12}"
#define OUT_PUT_DIR         "E:\innoDebug"//輸出檔案的路徑
#define IN_put_dir          "E:\kmsEnt"//輸入檔案的路徑
#define LICENSE             "E:\kmsEnt\download\len.txt"//協議的路徑
#define INSTALL_MODE        0 ;如果是更新標誌位為1,如果是安裝標誌位為0,到時候根據情況需要手動更新標誌位
#define WEB_URL             "Login.aspx"


#if (SERIES == "XXXX")
  #define MyAppName "KMS-Enterprise"
  #define MyAppVersion "1.0"
  #define MyAppPublisher "XXXX"
  #define MyAppURL "http://www.****.com.cn/"
  #define MyDirName "XXXX"
  #define OutAppName
  #define MyAppUninstallName "KMS_Uninstall"
#endif
[Setup]
; 注意: AppId 的值是唯一識別這個程式的標誌。
; 不要在其他程式中使用相同的 AppId 值。
; (在編譯器中點選選單“工具 -> 產生 GUID”可以產生一個新的 GUID)
AppId={{#MyAppId}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={sd}\{#MyDirName}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir={#OUT_PUT_DIR}
OutputBaseFilename={#MyAppName} V{#MyAppVersion}
LicenseFile={#LICENSE}
;Password={#PASSWORD}
Compression=lzma
SolidCompression=yes
;ChangesEnvironment=yes
;AlwaysRestart=yes

[Languages]
//Name: "default"; MessagesFile: "compiler:Default.isl"
Name: "english"; MessagesFile: "compiler:Languages\English.isl"

[License]

[Files]//輸入的檔案資訊
Source: "{#IN_put_dir}\*"; DestDir: "{app}";
Source: "{#IN_put_dir}\download\*"; DestDir: "{app}\download";Flags: recursesubdirs createallsubdirs
Source: "{#IN_put_dir}\download\kmsnew.sql"; Flags: dontcopy
//Source: "{#FILE_URL}\KMS_Pro.exe"; DestDir: "{app}"; Flags: ignoreversion
//Source: "{#FILE_URL}\..\Backup\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs uninsneveruninstall; Components: main
//Source: "{#FILE_URL}\..\Socket\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs uninsneveruninstall; Components: datebase
//Source: "{#FILE_URL}\..\MySQL\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs uninsneveruninstall; Components: datebase
//Source: "{#FILE_URL}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: main
//Source: "{#FILE_URL}\..\Dll\X86\*"; DestDir: {app}; Flags: ignoreversion uninsrestartdelete; Components: main

[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{app}\{#MyAppURL}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{app}\{#MyAppUninstallName}.exe"
Name: "{userdesktop}\{#MyAppName}"; Filename: "{code:GetURLDir}";

[Run]
Filename: "{app}\download\AccessDatabaseEngine_X64.exe";Check:IsWin64;Flags:waituntilterminated;
Filename: "{app}\download\AccessDatabaseEngine.exe";Check:Not IsWin64;Flags:waituntilterminated;
//Filename: "{app}\download\jiaoben.bat";Flags:waituntilterminated;
//Filename: "{app}\Driver\CP210xVCPInstaller_x64.exe";Tasks:yes; Check:IsWin64;
//Filename: "{app}\Driver\CP210xVCPInstaller_x86.exe";Tasks:yes; Check:Not IsWin64;
//Filename: "{app}\MessageCatDriver\PL2303_Prolific_DriverInstaller_x86.exe";Tasks:yes2;

[ISFormDesigner]
WizardForm=FF0A005457495A415244464F524D003010A608000054504630F10B5457697A617264466F726D0A57697A617264466F726D0C436C69656E74486569676874034C010B436C69656E74576964746803F1010D4578706C6963697457696474680301020E4578706C696369744865696768740373010D506978656C73506572496E636802600A54657874486569676874020C00F10A544E6577427574746F6E0A4E657874427574746F6E074F6E436C69636B07105F4E657874427574746F6E436C69636B0000F10C544E65774E6F7465626F6F6B0D4F757465724E6F7465626F6F6B00F110544E65774E6F7465626F6F6B5061676509496E6E65725061676500F10C544E65774E6F7465626F6F6B0D496E6E65724E6F7465626F6F6B00F110544E65774E6F7465626F6F6B506167651453656C656374436F6D706F6E656E74735061676500F10C544E6577436F6D626F426F780A5479706573436F6D626F064865696768740214000000F110544E65774E6F7465626F6F6B506167651653656C65637450726F6772616D47726F757050616765084E6578745061676507094949537365727665720000F110544E65774E6F7465626F6F6B506167650F53656C6563745461736B73506167650C50726576696F757350616765070953514C536572766572000010544E65774E6F7465626F6F6B50616765094949537365727665720E506172656E7453686F7748696E74080853686F7748696E74080743617074696F6E060A494953205365727665720B4465736372697074696F6E06164949532053657276657220496E666F726D6174696F6E0C50726576696F757350616765071653656C65637450726F6772616D47726F757050616765084E65787450616765070953514C5365727665720006544C6162656C0A6C62536974654E616D65044C656674021703546F700233055769647468023606486569676874020C0743617074696F6E060953697465204E616D65000006544C6162656C096C624E657753697465044C656674021703546F70025E055769647468023606486569676874020C0743617074696F6E06095369746520506F7274000006544C6162656C064C6162656C32044C656674021103546F70027E055769647468023C06486569676874020C0743617074696F6E060A49502041646472657373000006544C6162656C064C6162656C33044C656674021D03546F70039E00055769647468023006486569676874020C0743617074696F6E060841707020506F6F6C00000A544E6577427574746F6E0D62746E436F6E6E656374494953044C656674020903546F70020605576964746802630648656967687402190743617074696F6E060B436F6E6E65637420494953085461624F726465720200074F6E436C69636B071262746E436F6E6E656374494953436C69636B00000A544E6577427574746F6E0D62746E43726561746553697465044C65667403030103546F70039600055769647468026B0648656967687402190743617074696F6E060B4372656174652053697465085461624F726465720201074F6E436C69636B071262746E43726561746553697465436C69636B000008544E6577456469740853697465506F7274044C656674025703546F70025605576964746803920006486569676874021407496D654E616D651209000000378C4C6BFC62F397938F6551D56C20003200085461624F726465720203000008544E65774564697408536974654E616D65044C656674025703546F700233055769647468039200064865696768740214085461624F726465720202000008544E65774564697406536974654970044C656674025603546F700276055769647468039200064865696768740214085461624F72646572020400000C544E6577436F6D626F426F780A4C7374417070706F6F6C044C656674025603546F7003960005576964746803910006486569676874021406437572736F72070B637248616E64506F696E74055374796C65070E637344726F70446F776E4C6973740A4974656D486569676874020C085461624F72646572020500000010544E65774E6F7465626F6F6B506167650953514C5365727665720E506172656E7453686F7748696E74080853686F7748696E74080743617074696F6E060A53514C205365727665720B4465736372697074696F6E061553514C2053657276657220496E666F6D6174696F6E0C50726576696F7573506167650709494953736572766572084E65787450616765070F53656C6563745461736B73506167650006544C6162656C076C6253716C4970044C656674022D03546F700222055769647468026606486569676874020C0743617074696F6E06115365727665722049502041646472657373000006544C6162656C064C6162656C31044C656674025703546F700252055769647468023C06486569676874020C0743617074696F6E060A4C6F67696E204E616D65000006544C6162656C056C62507764044C656674026303546F70027E055769647468023006486569676874020C0743617074696F6E060850617373776F7264000008544E6577456469740865647453716C4970044C65667403C20003546F70021E055769647468027906486569676874021407496D654E616D651209000000378C4C6BFC62F397938F6551D56C20003200085461624F726465720200000008544E657745646974086564744C6F67696E044C65667403C20003546F70024E055769647468027906486569676874021407496D654E616D651209000000378C4C6BFC62F397938F6551D56C20003200085461624F72646572020100000A544E6577427574746F6E0D62746E53716C436F6E74656374044C65667403D00003546F7003AD00055769647468026B0648656967687402190743617074696F6E060F437265617465204461746162617365085461624F726465720203074F6E436C69636B071262746E53716C436F6E74656374436C69636B00000D5450617373776F7264456469740670776453716C044C65667403C20003546F70027A0557696474680279064865696768740214085461624F72646572020200000000000000

[Code]
{ RedesignWizardFormBegin } // 不要刪除這一行程式碼。
// 不要修改這一段程式碼,它是自動生成的。
var
  OldEvent_NextButtonClick: TNotifyEvent;
  IISserver: TWizardPage;
  lbSiteName: TLabel;
  lbNewSite: TLabel;
  Label2: TLabel;
  Label3: TLabel;
  btnConnectIIS: TNewButton;
  btnCreateSite: TNewButton;
  SitePort: TNewEdit;
  SiteName: TNewEdit;
  SiteIp: TNewEdit;
  LstApppool: TNewComboBox;
  SQLServer: TWizardPage;
  lbSqlIp: TLabel;
  Label1: TLabel;
  lbPwd: TLabel;
  edtSqlIp: TNewEdit;
  edtLogin: TNewEdit;
  btnSqlContect: TNewButton;
  pwdSql: TPasswordEdit;
   update:Integer;IISflag:Integer;Sqlflag:Integer;

procedure _NextButtonClick(Sender: TObject); forward;
procedure btnConnectIISClick(Sender: TObject); forward;
procedure btnCreateSiteClick(Sender: TObject); forward;
procedure btnSqlContectClick(Sender: TObject); forward;

procedure InitializeWizard;
begin
  { 建立自定義嚮導頁面 }
  IISserver := CreateCustomPage(wpSelectProgramGroup, 'IIS Server', 'IIS Server Information');
  SQLServer := CreateCustomPage(IISserver.ID, 'SQL Server', 'SQL Server Infomation');

  with WizardForm.NextButton do
  begin
    OldEvent_NextButtonClick := OnClick;
    OnClick := @_NextButtonClick;
  end;

  { IISserver }
  with IISserver.Surface do
  begin
    ShowHint := False;
  end;

  { lbSiteName }
  lbSiteName := TLabel.Create(WizardForm);
  with lbSiteName do
  begin
    Parent := IISserver.Surface;
    Caption := 'Site Name';
    Left := ScaleX(23);
    Top := ScaleY(51);
    Width := ScaleX(54);
    Height := ScaleY(12);
  end;

  { lbNewSite }
  lbNewSite := TLabel.Create(WizardForm);
  with lbNewSite do
  begin
    Parent := IISserver.Surface;
    Caption := 'Site Port';
    Left := ScaleX(23);
    Top := ScaleY(94);
    Width := ScaleX(54);
    Height := ScaleY(12);
  end;

  { Label2 }
  Label2 := TLabel.Create(WizardForm);
  with Label2 do
  begin
    Parent := IISserver.Surface;
    Caption := 'IP Address';
    Left := ScaleX(17);
    Top := ScaleY(126);
    Width := ScaleX(60);
    Height := ScaleY(12);
  end;

  { Label3 }
  Label3 := TLabel.Create(WizardForm);
  with Label3 do
  begin
    Parent := IISserver.Surface;
    Caption := 'App Pool';
    Left := ScaleX(29);
    Top := ScaleY(158);
    Width := ScaleX(48);
    Height := ScaleY(12);
  end;

  { btnConnectIIS }
  btnConnectIIS := TNewButton.Create(WizardForm);
  with btnConnectIIS do
  begin
    Parent := IISserver.Surface;
    Left := ScaleX(9);
    Top := ScaleY(6);
    Width := ScaleX(99);
    Height := ScaleY(25);
    Caption := 'Connect IIS';
    OnClick := @btnConnectIISClick;
  end;

  { btnCreateSite }
  btnCreateSite := TNewButton.Create(WizardForm);
  with btnCreateSite do
  begin
    Parent := IISserver.Surface;
    Left := ScaleX(259);
    Top := ScaleY(150);
    Width := ScaleX(107);
    Height := ScaleY(25);
    Caption := 'Create Site';
    OnClick := @btnCreateSiteClick;
  end;

  { SitePort }
  SitePort := TNewEdit.Create(WizardForm);
  with SitePort do
  begin
    Parent := IISserver.Surface;
    Left := ScaleX(87);
    Top := ScaleY(86);
    Width := ScaleX(146);
    Height := ScaleY(20);
  end;

  { SiteName }
  SiteName := TNewEdit.Create(WizardForm);
  with SiteName do
  begin
    Parent := IISserver.Surface;
    Left := ScaleX(87);
    Top := ScaleY(51);
    Width := ScaleX(146);
    Height := ScaleY(20);
  end;

  { SiteIp }
  SiteIp := TNewEdit.Create(WizardForm);
  with SiteIp do
  begin
    Parent := IISserver.Surface;
    Left := ScaleX(86);
    Top := ScaleY(118);
    Width := ScaleX(146);
    Height := ScaleY(20);
  end;

  { LstApppool }
  LstApppool := TNewComboBox.Create(WizardForm);
  with LstApppool do
  begin
    Parent := IISserver.Surface;
    Left := ScaleX(86);
    Top := ScaleY(150);
    Width := ScaleX(145);
    Height := ScaleY(20);
    Cursor := crHand;
    Style := csDropDownList;
  end;

  btnConnectIIS.TabOrder := 0;
  btnCreateSite.TabOrder := 1;
  SiteName.TabOrder := 2;
  SitePort.TabOrder := 3;
  SiteIp.TabOrder := 4;
  LstApppool.TabOrder := 5;

  { SQLServer }
  with SQLServer.Surface do
  begin
    ShowHint := False;
  end;

  { lbSqlIp }
  lbSqlIp := TLabel.Create(WizardForm);
  with lbSqlIp do
  begin
    Parent := SQLServer.Surface;
    Caption := 'Server IP Address';
    Left := ScaleX(45);
    Top := ScaleY(34);
    Width := ScaleX(102);
    Height := ScaleY(12);
  end;

  { Label1 }
  Label1 := TLabel.Create(WizardForm);
  with Label1 do
  begin
    Parent := SQLServer.Surface;
    Caption := 'Login Name';
    Left := ScaleX(87);
    Top := ScaleY(82);
    Width := ScaleX(60);
    Height := ScaleY(12);
  end;

  { lbPwd }
  lbPwd := TLabel.Create(WizardForm);
  with lbPwd do
  begin
    Parent := SQLServer.Surface;
    Caption := 'Password';
    Left := ScaleX(99);
    Top := ScaleY(126);
    Width := ScaleX(48);
    Height := ScaleY(12);
  end;

  { edtSqlIp }
  edtSqlIp := TNewEdit.Create(WizardForm);
  with edtSqlIp do
  begin
    Parent := SQLServer.Surface;
    Left := ScaleX(194);
    Top := ScaleY(30);
    Width := ScaleX(121);
    Height := ScaleY(20);
  end;

  { edtLogin }
  edtLogin := TNewEdit.Create(WizardForm);
  with edtLogin do
  begin
    Parent := SQLServer.Surface;
    Left := ScaleX(194);
    Top := ScaleY(78);
    Width := ScaleX(121);
    Height := ScaleY(20);
  end;

  { btnSqlContect }
  btnSqlContect := TNewButton.Create(WizardForm);
  with btnSqlContect do
  begin
    Parent := SQLServer.Surface;
    Left := ScaleX(208);
    Top := ScaleY(173);
    Width := ScaleX(107);
    Height := ScaleY(25);
    Caption := 'Create Database';
    OnClick := @btnSqlContectClick;
  end;

  { pwdSql }
  pwdSql := TPasswordEdit.Create(WizardForm);
  with pwdSql do
  begin
    Parent := SQLServer.Surface;
    Left := ScaleX(194);
    Top := ScaleY(122);
    Width := ScaleX(121);
    Height := ScaleY(20);
  end;

  edtSqlIp.TabOrder := 0;
  edtLogin.TabOrder := 1;
  pwdSql.TabOrder := 2;
  btnSqlContect.TabOrder := 3;

{ ReservationBegin }
  // 這一部分是提供給你的,你可以在這裡輸入一些補充程式碼。

{ ReservationEnd }
end;
// 不要修改這一段程式碼,它是自動生成的。
{ RedesignWizardFormEnd } // 不要刪除這一行程式碼。
//頁面改變時執行的系統預設的函式
procedure CurPageChanged(CurPageID: Integer);
var
ErrorCode: Integer;
IniPortLines: TArrayOfString;
sLi: TStringList;
i:Integer;
j:Integer;//MgdVersion
test:String;
begin
update:={#INSTALL_MODE};//如果是更新標誌位為1,如果是安裝標誌位為0,到時候根據情況需要手動更新標誌位 InitializeWizard update:Integer;IISflag:Integer;Sqlflag:Integer;
if update=0 then
begin
if CurPageID = IISserver.ID then
begin
if IISflag=0 then
begin
ShellExec('open', ExpandConstant('{cmd}'), ' /c C:\Windows\System32\inetsrv\appcmd.exe list APPPOOL >c:\f.txt', '', SW_HIDE, ewNoWait, ErrorCode);//將應用程式池的資訊全部寫入C盤中的一個檔案內
Sleep(1000);
LoadStringsFromFile( 'c:\f.txt', IniPortLines );//讀取檔案內的字串,以陣列的形式將字串儲存起來
sLi := TStringList.Create;
for i:= 0 to GetArrayLength(IniPortLines)-1 do //for迴圈
  begin
  j:=Pos('" (',IniPortLines[i]);
  IniPortLines[i]:=Copy(IniPortLines[i],10,j-10);//擷取字串裡面的欄位
  sLi.Add(IniPortLines[i]);//將資料新增進入TSringList陣列中
  end;
   LstApppool.Items:=sLi;
WizardForm.NextButton.Enabled:=false;//控制頁面上下一步按鈕的是否有用
DeleteFile('c:\f.txt');//刪除檔案
end
else
  WizardForm.NextButton.Enabled:=true;//控制頁面上下一步按鈕的是否有用
end;
if CurPageID=SQLServer.ID then //根據頁面的id去判斷現在處於哪個頁面
begin
  if Sqlflag=0 then
    begin
    WizardForm.NextButton.Enabled:=false;//控制頁面上下一步按鈕的是否有用
    end
    else
    WizardForm.NextButton.Enabled:=true;//控制頁面上下一步按鈕的是否有用
end;
end
else
begin
 SiteName.Enabled:=false;//控制頁面上按鈕是否能用
 Siteport.Enabled:=false;//控制頁面上按鈕是否能用
 SiteIp.Enabled:=false;//控制頁面上按鈕是否能用
 edtSqlIp.Enabled:=false;//控制頁面上按鈕是否能用
 edtLogin.Enabled:=false;//控制頁面上按鈕是否能用
 pwdSql.Enabled:=false;//控制頁面上按鈕是否能用
 btnSqlContect.Enabled:=false;//控制頁面上按鈕是否能用
 btnCreateSite.Enabled:=false;//控制頁面上按鈕是否能用
 LstApppool.Enabled:=false;//控制頁面上按鈕是否能用
end;
end;

procedure _NextButtonClick(Sender: TObject);
begin
  OldEvent_NextButtonClick(Sender);
end;

procedure btnCreateSiteClick(Sender: TObject);
var
  a :Integer;
  dirstr:String;
  name:String;//網站名稱引數
  portk:String;//埠引數
  ipadr:String;//ip引數
  ErrorCode: Integer;//錯誤變數
  IniPortLines: TArrayOfString;//陣列
  count:Integer;//計數
begin
   dirstr:=ExpandConstant('{app}');//獲取當前安裝的路勁
   name:=SiteName.text;//將頁面上填寫的資訊存入變數裡面
   portk:=SitePort.text;//將頁面上填寫的資訊存入變數裡面
   ipadr:=SiteIp.text;//將頁面上填寫的資訊存入變數裡面
   //ShellExec('open', ExpandConstant('{cmd}'), '/c C:\Windows\System32\inetsrv', '', SW_HIDE, ewNoWait, ErrorCode);
   ShellExec('open', ExpandConstant('{cmd}'), ' /c C:\Windows\System32\inetsrv\appcmd.exe list site "'+name+'" >c:\b.txt', '', SW_HIDE, ewNoWait, ErrorCode);//在iis裡面查詢自己填寫的網站名稱是否存在
   Sleep(1000);
   LoadStringsFromFile( 'c:\b.txt', IniPortLines );//將檔案裡面的資訊以字串的形式取出來
   count:=GetArrayLength(IniPortLines);//獲取字串的長度
   if count>0 then
   begin
   MsgBox('The Site Name has Existed!',mbConfirmation,MB_OK);
   end
   else
   begin
   ShellExec('open', ExpandConstant('{cmd}'), '/c C:\Windows\System32\inetsrv\appcmd.exe add site /name:"'+name+'" /bindings:http/'+ipadr+':'+portk+': /physicalPath:"'+dirstr+'" /applicationDefaults.applicationPool:"'+LstApppool.Text+'"', '', SW_HIDE, ewNoWait, ErrorCode);//新增網站
   Sleep(1000);
   //ShellExec('open', ExpandConstant('{cmd}'), '/c C:\Windows\System32\inetsrv\appcmd.exe set site /name:"'+name+'" /applicationDefaults.applicationPool:"ASP.net v4.0"', '', SW_HIDE, ewNoWait, ErrorCode);
   DeleteFile('c:\b.txt');//刪除檔案
   MsgBox('Site Made Success!',mbConfirmation,MB_OK);
   ShellExec('open', ExpandConstant('{cmd}'), '/c netsh advfirewall firewall add rule name="KmsEnterprise" dir=in action=allow protocol=TCP localport='+portk, '', SW_HIDE, ewNoWait, ErrorCode);//開啟防火牆的埠
   if update=0 then
   begin
   WizardForm.NextButton.Enabled:=true;//控制頁面按鈕是否有用
   IISflag:=1;//標誌位資訊,全域性變數
   end
   end
   
   //MsgBox(dirstr+':'+name+':'+portk+':'+ipadr,mbConfirmation,MB_OK);
  //MsgBox(ExpandConstant('{app}'),mbConfirmation,MB_OK);


end;

//獲取桌面快捷方式的網址的函式
function GetURLDir( Param: String ) : String;
var
  URLDir          : String;
begin
  URLDir := 'http://'+SiteIp.text+':'+ SitePort.Text +'/{#WEB_URL}';//獲取網址
  Result := URLDir;//返回的引數
end;

procedure btnSqlContectClick(Sender: TObject);
var
  a :Integer;
  sqlip:String;
  sqlUser:string;
  sqlPwd:String;
  ErrorCode: Integer;
  IniPortLines: TArrayOfString;
  count:Integer;
  dIniPortLines: TArrayOfString;
  Path:String;
begin
ExtractTemporaryFile('kmsnew.sql');//解壓臨時檔案,下面獲取安裝包內的檔案用的
sqlip:=edtSqlIp.text;//獲取頁面輸入資訊
sqlUser:=edtLogin.text;//獲取頁面輸入資訊
sqlPwd:=pwdSql.text;//獲取頁面輸入資訊
ShellExec('open', ExpandConstant('{cmd}'), '/c osql.exe -S '+sqlip+' -U '+sqlUser+' -P '+sqlPwd+' -Q >c:\c.txt', '', SW_HIDE, ewNoWait, ErrorCode);//驗證輸入的資料庫資訊是否正確
Sleep(1000);
LoadStringsFromFile( 'c:\c.txt', IniPortLines );//讀取出檔案內的資訊
count:=GetArrayLength(IniPortLines);//獲取陣列長度
if count=0 then
begin
 ShellExec('open', ExpandConstant('{cmd}'), '/c osql.exe -S '+sqlip+' -U '+sqlUser+' -P '+sqlPwd+' -d kms -Q >c:\d.txt', '', SW_HIDE, ewNoWait, ErrorCode);//驗證資料庫名是否已經存在
 Sleep(1000);
 LoadStringsFromFile( 'c:\d.txt', dIniPortLines ); //讀取出檔案內的資訊
count:=GetArrayLength(dIniPortLines);//獲取陣列長度
  if count=0 then
  begin
  MsgBox('Database Create Success!',mbConfirmation,MB_OK);//彈出框
  if update=0 then
  begin
  WizardForm.NextButton.Enabled:=true;
  Sqlflag:=1;
  end
  end
  else begin
     //建立資料庫和資料庫表
     //建立資料庫
      ShellExec('open', ExpandConstant('{cmd}'), '/c osql.exe -S '+sqlip+' -U '+sqlUser+' -P '+sqlPwd+' -Q "create database kms"', '', SW_HIDE, ewNoWait, ErrorCode);//建立資料庫
      Sleep(1000);
      //執行kmsnew.sql檔案建立資料庫表
      //Path:= ExpandConstant('{app}')+'\download\kmsnew.sql';{userappdata} ExpandConstant('{tmp}/kmsnew.sql')
      //Path:= ExpandConstant('{#IN_put_dir}')+'\download\kmsnew.sql';
       Path:= ExpandConstant('{tmp}/kmsnew.sql'); //獲取安裝包內的檔案
      ShellExec('open', ExpandConstant('{cmd}'), '/c osql.exe -S '+sqlip+' -U '+sqlUser+' -P '+sqlPwd+' -d kms -i '+ExpandConstant('{tmp}')+'/kmsnew.sql', '', SW_HIDE, ewNoWait, ErrorCode);//建立資料庫表
      MsgBox('Database Create Success!!',mbConfirmation,MB_OK);
      if update=0 then
      begin
      WizardForm.NextButton.Enabled:=true;//控制頁面按鈕是否有用
      Sqlflag:=1;//標誌位引數
      end
  end

end
else
begin
//連線sqlserver失敗
 MsgBox('Sql Server Connect Failed,Please Check The Password!',mbConfirmation,MB_OK);
end;
DeleteFile('c:\c.txt');//刪除檔案
DeleteFile('c:\d.txt');//刪除檔案
  a := 1;
end;

procedure btnConnectIISClick(Sender: TObject);
var
  a :Integer;
  ErrorCode: Integer;
  IniPortLines: TArrayOfString;
  count:Integer;
  Path:String;
  IIS:Variant;
begin
//IIsNext.Enabled:=true;
//ExtractTemporaryFile('jiaoben.bat');//解壓臨時檔案,下面獲取安裝包內的檔案用的
//begin
try
     IIS:= CreateOleObject('IISNamespace');
     IIS:=Unassigned;
     MsgBox('IIS Connect Success!',mbConfirmation,MB_OK);
except
    RaiseException('無法檢測到iis伺服器,請確認是否正確安裝\n如確認已安裝完成請建立站點!');//.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)

end;

//ShellExec('open', ExpandConstant('{cmd}'), '/c iisreset /status >c:\a.txt', '', SW_HIDE, ewNoWait, ErrorCode);
//Sleep(1000);
 //LoadStringsFromFile( 'c:\a.txt', IniPortLines );
 //count:=GetArrayLength(IniPortLines);
 //if count = 7 then
 //begin
 //MsgBox('IIS Connect Success!',mbConfirmation,MB_OK);
 //end else
 //begin
      //Path:= ExpandConstant('{tmp}')+'/jiaoben.bat';
      //Path:=ExpandConstant('{cmd}');
      //ShellExec('open', ExpandConstant('{cmd}'), '/c '+ExpandConstant('{tmp}')+'/jiaoben.bat', '', SW_HIDE, ewNoWait, ErrorCode);
      //Sleep(2000);
      //MsgBox('IIS Connect Failed!!',mbConfirmation,MB_OK);
 //end;
 //Sleep(1000);
 //DeleteFile('c:\a.txt');
  //a := 1;
end;


{******************************************************************************
 *   設定環境變數函式
 ******************************************************************************}
procedure SetEnv( aEnvName, aEnvValue: String; aIsInstall , aIsAll : Boolean );
var
  sOrgValue             : String;
  x,len                 : Integer;
begin
  RegQueryStringValue( HKEY_LOCAL_MACHINE ,
    'SYSTEM\CurrentControlSet\Control\Session Manager\Environment' ,
    aEnvName, sOrgValue ) ;
  sOrgValue := Trim( sOrgValue );
  begin
    x   := pos( Uppercase( aEnvValue ) , Uppercase( sOrgValue ) );
    len := length(aEnvValue);
    if aIsInstall then                                                         //是安裝還是反安裝
    begin
      if not aIsAll then
      begin
          if length(sOrgValue) > 0 then
            aEnvValue := ';'+ aEnvValue;

          if x = 0 then
            Insert( aEnvValue , sOrgValue , length(sOrgValue) + 1 );
      end else
      begin
        sOrgValue := Trim( aEnvValue );
      end;
    end else
    begin
      if x > 0 then
        Delete( sOrgValue , x , len );
      if length( sOrgValue )= 0 then
      begin
        RegDeleteValue(HKEY_LOCAL_MACHINE,
          'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
          aEnvName);
        exit;
      end;
    end;
    StringChange( sOrgValue, ';;' , ';' );
    RegWriteStringValue(HKEY_LOCAL_MACHINE,
      'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
      aEnvName, sOrgValue ) ;
  end;
end;

{******************************************************************************
 *   修改配置檔案,安裝程式完成之後執行的函式
 ******************************************************************************}
procedure CurStepChanged( CurStep: TSetupStep );
var
  IniFile, OldString, NewString     : String;
  IniFileLines                      : TArrayOfString;
  i                                 : Integer;
  uninspath, uninsname, NewUninsName, MyAppName, MyAppId: string;
begin
  if CurStep = ssDone then
  begin
    IniFile   := ExpandConstant('{app}\Web.config');                         // 你的 INI 檔名
    OldString := '<add key="ConnectionString" value="Data Source=192.168.0.29;Initial Catalog=kms;Persist Security Info=false;Integrated Security=false;uid=admin;pwd=password"/>';                                                  // 要替換的舊字串
    NewString := '<add key="ConnectionString"    value="Data Source='+edtSqlIp.text+';Initial Catalog=kms;Persist Security Info=false;Integrated Security=false;uid='+edtLogin.text+';pwd='+pwdSql.text+'"/>';                               // 新字串
    //StringChange( NewString , '\', '/');
    //NewString := NewString + '/' ;
    //StringChange( NewString , '//', '/');

    LoadStringsFromFile( IniFile , IniFileLines );
    for i:= 0 to GetArrayLength(IniFileLines)-1 do  //迴圈語句
      if ( Pos( OldString , IniFileLines[i] ) > 0) then //在字串中存在
        StringChange(IniFileLines[i], OldString, NewString);//將新的字串替換老的字串
    SaveStringsToFile( IniFile , IniFileLines, False );//將資訊重新寫入檔案
    //SetEnv( 'MYSQL_HOME' , ExpandConstant('{app}\MySQL' ), true , true );
    //SetEnv( 'PATH' , ExpandConstant('%MYSQL_HOME%\bin' ), true ,false );
  end;

  if CurStep=ssDone then
  begin
  // 指定新的登錄檔名,請相應修改!
  //MyAppId := '{C893C605-CC64-44F4-B60B-30998FE892DF}';
  MyAppId := '{#MyAppId}';
  //NewUninsName := 'KMS_Uninstall';
  NewUninsName := '{#MyAppUninstallName}';

  // 以下重新命名解除安裝檔案
  uninspath:= ExtractFilePath(ExpandConstant('{uninstallexe}'));
  uninsname:= Copy(ExtractFileName(ExpandConstant('{uninstallexe}')),1,8);
  RenameFile(uninspath + uninsname + '.exe', uninspath + NewUninsName + '.exe');
  RenameFile(uninspath + uninsname + '.dat', uninspath + NewUninsName + '.dat');
  // 以下修改相應的登錄檔內容
  if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + MyAppId + '_is1') then
    begin
    RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + MyAppId + '_is1', 'UninstallString', '"' + uninspath + NewUninsName + '.exe"');
    RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + MyAppId + '_is1', 'QuietUninstallString', '"' + uninspath + NewUninsName + '.exe" /SILENT');
    end;
  end;
end;

{******************************************************************************
 *   解除安裝
 ******************************************************************************}
procedure CurUninstallStepChanged (CurUninstallStep: TUninstallStep );
var
  IsAppRunning: boolean;
begin
  case CurUninstallStep of
  usUninstall:
  begin
   
  end;
  usPostUninstall:
  begin // 解除安裝完成
    // MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall just finished.', mbInformation, MB_OK);
    // ...insert code to perform post-uninstall tasks here...
    //ShellExec('open', 'http://www.dreams8.com', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  end;
end;
end;