Use Inno Setup to package. NET program, and install. NET framework__.net automatically

Source: Internet
Author: User
Tags error code

Inno Setup is a setup package production program under a Windows system. It is free (and allows for free commercial use). Official website: http://www.jrsoftware.org/

Although. NET can use VS to package the installation package, but customization is definitely not as Inno Setup, the basic use here does not do too much introduction. Let's Google it.

When we are developing. NET clients the. NET Framework is a more troubling issue, such as a WPF program size of hundreds of K, but installing a dozens of M. NET Framework. But there is no way. There are two ways to package the. NET Framework into the installation package, one to download the. NET Framework and then install it online.

Each has its own shortcomings and advantages. Choose your own choice.

Inno Setup Packages the. Net Framework to the installation package method script:

; The script is generated by the Inno Setup Script Wizard.;

For more information about creating Inno Setup script files, consult the Help documentation. #define MYAPPNAME "MYAPP" #define MYAPPVERSION "1.0" #define Includeframework true #define isexternal "" #define Myapppubl Isher "APP" #define MYAPPURL "http://www.MyApp.cn" #define MYAPPEXENAME "MyApp.exe" [Setup]; Note: The value of AppID is uniquely identified for the application.; Do not use the same AppID value for other installers.; (Generate a new GUID, click the tool | To generate a GUID in the IDE.) appid={{b0c52f2e-939f-4ce2-89f3-2f0677584526} appname={#MyAppName} appversion={#MyAppVersion}; appvername={#MyAppName} {#MyAppVersion} apppublisher={#MyAppPublisher} apppublisherurl={#MyAppURL} appsupporturl={ #MyAppURL} appupdatesurl={#MyAppURL} defaultdirname={pf}\{#MyAppName} defaultgroupname={#MyAppName} outputdir=e:\ Step Compression=lzma solidcompression=yes #if includeframework outputbasefilename=setup_fw #else OutputBaseFilename= Setup #endif [Languages] Name: "Chinesesimp"; Messagesfile: "COMPILER:DEFAULT.ISL" [Tasks] Name: "Desktopicon"; Description: "{Cm:createdesktopicon}"; Groupdescription: "{cm:additionalicons}"; Flags:unchecked; onlybelowversion:0,6.1 [Files] Source: "E:\MyApp\MyApp.exe"; Destdir: "{app}"; flags:ignoreversion {#IsExternal} #if includeframework Source: "D:\ development \dotnetfx40_full_x86_x64.exe"; Destdir: "{tmp}"; flags:ignoreversion {#IsExternal}; Check:needsframework #endif; Note: Do not use "flags:ignoreversion" [Icons] Name: "{group}\{#MyAppName}" on any shared system files; Filename: ' {app}\{#MyAppExeName} ' Name: ' {commondesktop}\{#MyAppName} '; Filename: "{app}\{#MyAppExeName}"; Tasks:desktopicon [Run] #if includeframework Filename: {tmp}\dotnetfx40_full_x86_x64.exe; Parameters: "/Q:A/C:" "INSTALL/L/Q" "; Workingdir: {tmp}; Flags:skipifdoesntexist; Statusmsg: "Installing. NET Framework if needed" #endif Filename: {win}\microsoft.net\framework\v4.0.30319\caspol.exe; Parameters: "-q-machine-remgroup" "{#MyAppName}" "; Workingdir: {tmp}; Flags:skipifdoesntexist Runhidden;
STATUSMSG: "Setting program Access Permissions ..." Filename: {win}\microsoft.net\framework\v4.0.30319\caspol.exe; Parameters: "-q-machine-addgroup 1.2-url" "file://{app}/*" "Fulltrust-name" "{#MyAppName}" "; Workingdir: {tmp}; Flags:skipifdoesntexist Runhidden;

STATUSMSG: "Setting program Access Permissions ..."
[Uninstallrun] Filename: {win}\microsoft.net\framework\v4.0.30319\caspol.exe; Parameters: "-q-machine-remgroup" "{#MyAppName}" ";

Flags:skipifdoesntexist Runhidden;
[Code]//Indicates whether. NET Framework 2.0 is installed.
function isdotnet40detected (): boolean;
    var Success:boolean;
install:cardinal;
     Begin Success: = Regquerydwordvalue (HKLM, ' software\microsoft\net Framework setup\ndp\v4\full ', ' Install ', Install);
    Success: = Regquerydwordvalue (HKLM, ' software\microsoft\net Framework setup\ndp\v2.0.50727 ', ' Install ', Install);
Result: = Success and (install = 1);

End RETURNS opposite of isdotnet20detected function//remember this to the Files section above function Needsframew
Ork (): Boolean;
Begin Result: = (isdotnet40detected = false);



End FunCtion Getcustomsetupexitcode (): Integer;
      Begin IF (isdotnet40detected = false) THEN begin MsgBox ('. NET Framework not properly installed! ', Mberror, MB_OK);

Result: =-1 end;
Uninstall program function Initializeuninstall (): Boolean;
  Begin Result: = MsgBox (' Uninstall program: ' #13 #13 ' you really want to uninstall the program? ', Mbconfirmation, mb_yesno) = Idyes;
If result = False then//MsgBox (' Initializeuninstall: ' #13 #13 ' Ok, Bye Bye. ', mbinformation, MB_OK);


End
Procedure curuninstallstepchanged (Curuninstallstep:tuninstallstep);
var Errorcode:integer; Begin case Curuninstallstep of Usuninstall:begin//msgbox (' Uninstall program: ' #13 #13 ' unloading ... ', mbinformation, MB
    _OK)//... insert code to perform pre-uninstall tasks here ... end;
        Uspostuninstall:begin//msgbox (' Uninstall program: ' #13 #13 ' uninstall complete. ', mbinformation, MB_OK);
        ... insert code to perform post-uninstall tasks ... Shellexec (' Open ', ' http://www.asiafinance.cn ', ', ', ', Sw_show, ewnowait, errorcode) end;
End End

Script Description:

The Web page opens automatically after the uninstall is complete, and the logic can be expanded freely inside.

Detects which framwork can find this node in the registry.

Inno Setup downloads and installs online. Netframwork

; The script is generated by the Inno Setup Script Wizard.;

For more information about creating Inno Setup script files, consult the Help documentation. #define MYAPPNAME "MYAPP" #define MYAPPVERSION "1.0" #define Myapppublisher "MyApp" #define MYAPPURL "http://www". myapp.cn/"#define MYAPPEXENAME" MyApp.exe "[Setup]; Note: The value of AppID is uniquely identified for the application.; Do not use the same AppID value for other installers.; (Generate a new GUID, click the tool | To generate a GUID in the IDE.) APPID={{769CC8AC-50C3-4776-95F5-A1ABF15A38F4} appname={#MyAppName} appversion={#MyAppVersion}; appvername={#MyAppName} {#MyAppVersion} apppublisher={#MyAppPublisher} apppublisherurl={#MyAppURL} appsupporturl={ #MyAppURL} appupdatesurl={#MyAppURL} defaultdirname={pf}\{#MyAppName} defaultgroupname={#MyAppName} outputdir=e:\ Step Outputbasefilename=myapp Compression=lzma Solidcompression=yes [Languages] Name: "Chinesesimp"; Messagesfile: "COMPILER:DEFAULT.ISL" [Tasks] Name: "Desktopicon"; Description: "{Cm:createdesktopicon}"; Groupdescription: "{cm:additionalicons}"; flags:unchecked; onlybelowversion:0,6.1 [Files] Source:c:\program Files\istool\isxdl.dll;
Flags:dontcopy; Source: "E:\MyApp\MyApp.exe"; Destdir: "{app}"; Flags:ignoreversion; Note: Do not use "flags:ignoreversion" [Icons] Name: "{group}\{#MyAppName}" on any shared system files; Filename: ' {app}\{#MyAppExeName} ' Name: ' {group}\{cm:uninstallprogram,{#MyAppName}} '; Filename: ' {uninstallexe} ' Name: ' {commondesktop}\{#MyAppName} '; Filename: "{app}\{#MyAppExeName}"; Tasks:desktopicon [Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:launchprogram,{#StringChange (myappname," & "," && ")}}";
  Flags:nowait postinstall skipifsilent [Code] var dotnetredistpath:string;
  Downloadneeded:boolean;
  Dotnetneeded:boolean;

memodependenciesneeded:string;
Procedure Isxdl_addfile (URL, Filename:pchar);
External ' isxdl_addfile@files:isxdl.dll stdcall ';
function Isxdl_downloadfiles (Hwnd:integer): Integer;
External ' isxdl_downloadfiles@files:isxdl.dll stdcall ';
function Isxdl_setoption (Option, Value:pchar): Integer;
External ' isxdl_setoption@files:isxdl.dll stdcall '; Const DOTNETREDISTURL = ' HTTP://WWW.MICRosoft.com/downloads/info.aspx?na=41&srcfamilyid=e5ad0459-cbcc-4b4f-97b6-fb17111cf544&srcdisplaylang=en &u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f2%2f562a10f9-c9f4-4313-a044-9c94e0a8fac8%

2fdotnetfx40_client_x86_x64.exe ';
  This URL is correct at the publication for. NET 3.5/

Local System for testing ...//Dotnetredisturl = ' http://192.168.1.1/dotnetfx35.exe ';

function Initializesetup (): Boolean;
  Begin Result: = TRUE;

  Dotnetneeded: = false; Check for required NetFx installation if (not regkeyexists (HKLM, ' software\microsoft\.
    netframework\policy\v4.0 ')) THEN BEGIN dotnetneeded: = true; if (not Isadminloggedon ()) THEN BEGIN MsgBox (' Gassoft needs the Microsoft. NET Framework to is installed by a Admin
      Istrator ', mbinformation, MB_OK);
    Result: = false;
      End ELSE begin memodependenciesneeded: = memodependenciesneeded + '. NET Framework ' #13; Dotnetredistpath: = EXPANDCOnstant (' {src}\dotnetfx35.exe ');
        If not fileexists (Dotnetredistpath) THEN begin Dotnetredistpath: = Expandconstant (' {tmp}\dotnetfx35.exe ');
          If not fileexists (Dotnetredistpath) THEN begin Isxdl_addfile (Dotnetredisturl, Dotnetredistpath);
        Downloadneeded: = true;
      End
      End
    Setinistring (' Install ', ' dotnetredist ', Dotnetredistpath, Expandconstant (' {tmp}\dep.ini '));
  End
End

End
function Nextbuttonclick (Curpage:integer): Boolean;
  var Hwnd:integer;

Resultcode:integer;

  Begin Result: = TRUE; If curpage = Wpready THEN BEGIN if (not regkeyexists (HKLM, ' software\microsoft\.

    netframework\policy\v4.0 ')) THEN BEGIN hWnd: = Strtoint (Expandconstant (' {wizardhwnd} ')); Don ' t try to init ISXDL if it's not needed because it'll error on < IE 3 if downloadneeded then BEGIN I
      Sxdl_setoption (' label ', ' downloading the Microsoft. NET Framework '); Isxdl_setoption (' des-c-r-i-p-tion ', ' You have not yet installed Microsoft. NET Framework. Please be patient and install to your computer when the download is complete.
      ');
    If Isxdl_downloadfiles (hWnd) = 0 Then result: = FALSE;
    End if (result = True) and (dotnetneeded = true) THEN BEGIN if Exec (Expandconstant (Dotnetredistpath), '/qb ', ', sw_show , ewwaituntilterminated, ResultCode) THEN BEGIN//handle success if necessary;
         ResultCode contains the "Exit code if not" (ResultCode = 0) THEN BEGIN result: = FALSE;
      End End ELSE begin//handle failure if necessary;
      ResultCode contains the error code result: = FALSE;
      End
    End
  End
End End

I detect is. Net Framework4.0, installation package size of about 48M, compared to 3.0 or a lot smaller.

The installation package is small when installed online, but downloading is more time-consuming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.