How To: Create A Setup.exe Package That Will Only Download VB Runtimes If Neccessary!
Posted on 2012-05-30 15:55 鹤唳九天 阅读(374) 评论(0) 编辑 收藏 举报正文:
Dont you hate having to distribute a 1.5mb setup exe because of the minority of people that do not have the visual basic 6 runtimes installed? I know for me, personally, it is extremely frustrating to know that my exe is 60kb, but my setup.exe is 1.5mb because it includes the runtimes.
Finally, after months of searching, I have a solution. Using innosetup, there is some code available that will make a setup.exe that can check if the runtimes are installed correctly, and if not, it will download them from the internet .
This will save you a lot of bandwidth, and people can download your applications in a heart beat instead of waiting for a 1.5mb download (especially if they are on dialup)
Code:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; please change following values accordingly to your application
#define _AppName "your app name"
#define _AppVer "1.00"
#define _AppPublisher "publisher"
#define _AppUrl "http://www.google.com"
#define _AppSetup "setup"
#define _AppFileName "Siw.exe"
#define _AppDwnUrl "http://www.yourserver.net/en/siw.exe"
#define _VBRFileName "VB6r.exe"
#define _VBRDwnUrl "http://download.microsoft.com/download/5/a/d/5ad868a0-8ecd-4bb0-a882-fe53eb7ef348/VB6.0-KB290887-X86.exe"
#define _SCKFileName "mswinsck.ocx"
#define _SCKDwnUrl "http://www.afreeocx.com/ocx/download/2844/mswinsck.ocx"
[Setup]
AppName = {#_AppName}
AppVerName = {#_AppName} {#_AppVer}
AppPublisher = {#_AppPublisher}
AppPublisherURL = {#_AppUrl}
AppSupportURL = {#_AppUrl}
AppUpdatesURL = {#_AppUrl}
DefaultDirName = {pf}{#_AppName}
DefaultGroupName = {#_AppName}
LicenseFile = filesLicense.rtf
OutputDir = .
OutputBaseFilename= {#_AppSetup}
Compression = lzma
SolidCompression = yes
AppVersion = {#_AppVer}
VersionInfoCompany = {#_AppPublisher}
VersionInfoCopyright = {#_AppPublisher}
VersionInfoTextVersion = {#_AppVer}
VersionInfoVersion = {#_AppVer}
WizardImageFile = filesSetupModern16.bmp
WizardSmallImageFile = filesSetupModernSmall16.bmp
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Icons]
Name: "{group}{#_AppName}"; Filename: "{app}{#_AppFileName}"
Name: "{group}{cm:ProgramOnTheWeb,{#_AppName}}"; Filename: "{#_AppUrl}"
Name: "{group}{cm:UninstallProgram,{#_AppName}}"; Filename: "{uninstallexe}"
[UninstallDelete]
Type: filesandordirs; Name: "{app}"
[Files]
Source: "filesisxdl.dll"; Flags: dontcopy
Source: "filesSetupModernSmall16.bmp"; Flags: dontcopy
[Run]
; running vbrun60sp6 in silent mode if was downloaded successfuly
Filename: "{tmp}{#_VBRFileName}"; Parameters: "/q:a /c /t:{tmp}"; StatusMsg: "Installing Visual Basic Runtime Files ..."; Flags: waituntilterminated skipifdoesntexist; Check: InstallVBR_Check;
Filename: "{tmp}vbrun60sp6.exe"; Parameters: "/q:a"; StatusMsg: "Installing Visual Basic Runtime Files ..."; Flags: waituntilterminated skipifdoesntexist; Check: InstallVBR_Check;
[$Main$]
var
Install_VBRun60Sp6: boolean;
Install_MSWinSck: boolean;
procedure isxdl_AddFile(URL, Filename: PChar); // functions needed for download
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';
procedure CheckVB6RuntimeFiles;
var
MS, LS: Cardinal;
i: integer;
VBFiles : array[0..5] of string;
vMS : array[0..5] of cardinal;
vLS : array[0..5] of cardinal;
begin
Install_VBRun60Sp6:= False;
Install_MSWinSck := False;
// here are file names and file versions stored in VB6 Runtime Sp6 - the latest pack that can be downloaded from microsoft
VBFiles[0] := 'asycfilt.dll'; vMS[0] := 131112; vLS[0] := 280166401; // v. 2.40.4275.1
VBFiles[1] := 'comcat.dll'; vMS[1] := 262215; vLS[1] := 95682561; // v. 4.71.1460.1
VBFiles[2] := 'msvbvm60.dll'; vMS[2] := 393216; vLS[2] := 6357074; // v. 6.00.9782
VBFiles[3] := 'oleaut32.dll'; vMS[3] := 131112; vLS[3] := 280166401; // v. 2.40.4275.1
VBFiles[4] := 'olepro32.dll'; vMS[4] := 327680; vLS[4] := 280166401; // v. 5.0.4275.1
VBFiles[5] := 'stdole2.tlb'; vMS[5] := 131112; vLS[5] := 280166401; // v. 2.40.4275.1
for i:=0 to 5 do // checking each file version
begin
MS:=0; LS:=0;
GetVersionNumbers(ExpandConstant('{sys}' + VBFiles[i]), MS, LS); // get the existing file version
if MS < vMS[i] then Install_VBRun60Sp6:=True; // if the existing file version is lower than
if MS = vMS[i] then if LS < vLS[i] then Install_VBRun60Sp6:=True; // version from vbrun60sp6 pack then we must download
end; // and install vbrun60sp6.exe
if not FileExists(ExpandConstant('{sys}{#_SCKFileName}')) then Install_MSWinSck:=True; // if mswinsck.ocx does not exist the we must
end; // download and install it
procedure InitializeWizard();
var
x: TWizardPage;
begin
CheckVB6RuntimeFiles; // during initialization checking what we must download and install
end;
function Download_AppFiles: Boolean;
var
hWnd: Integer;
URL, FileName: String;
begin
if not DirExists(ExpandConstant('{app}')) then CreateDir(ExpandConstant('{app}')); // since application file will be downloaded
isxdl_SetOption('title', ExpandConstant('Setup - {#_AppName}')); // directly to {app} folder the we must creat it if not exist
if WizardSilent then isxdl_SetOption('simple', 'Downloading application files...') else // if setup is started in silent mode then we will show downloading
begin // progress window in simple mode!
isxdl_SetOption('label', 'Downloading application files'); // Unfortunately it can't be hidden, to make setup totally silent!
isxdl_SetOption('description', 'Please wait while Setup is downloading required files to your computer.');
end;
try
FileName := ExpandConstant('{tmp}SetupModernSmall16.bmp');
if not FileExists(FileName) then ExtractTemporaryFile(ExtractFileName(FileName));
isxdl_SetOption('smallwizardimage', FileName);
except
end;
//turn off isxdl resume so it won't leave partially downloaded files behind
//resuming wouldn't help anyway since we're going to download to {tmp}
isxdl_SetOption('resume', 'false');
hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
URL := ExpandConstant('{#_AppDwnUrl}'); // adding application file to download list
FileName := ExpandConstant('{app}{#_AppFileName}');
isxdl_AddFile(URL, FileName);
if Install_VBRun60Sp6 then // if vb6runtime is needed the we add it to download list
begin
URL := ExpandConstant('{#_VBRDwnUrl}');
FileName := ExpandConstant('{tmp}{#_VBRFileName}');
isxdl_AddFile(URL, FileName);
end;
if Install_MSWinSck then // if MSWinSck.ocx is needed the we add it to download list
begin
URL := ExpandConstant('{#_SCKDwnUrl}');
FileName := ExpandConstant('{sys}{#_SCKFileName}');
isxdl_AddFile(URL, FileName);
end;
if isxdl_DownloadFiles(hWnd) = 0 then // starting download. If we get some download errors, the setup will continue anyway!
SuppressibleMsgBox('Setup could not download some files. Please try again later!' + #13#13 + 'Setup will now continue installing normally.', mbError, mb_Ok, idOk);
if Install_MSWinSck and FileExists(ExpandConstant('{sys}{#_SCKFileName}')) then // if MSWinSck.ocx was downloaded successfuly then
RegisterServer(False, ExpandConstant('{sys}{#_SCKFileName}'), False); // register file! I don't know if that is needed!
Result := True;
end;
function InstallVBR_Check: Boolean;
begin
Result := Install_VBRun60Sp6;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if (CurPageID = wpReady) then Result := Download_AppFiles
else Result := True;
end;
**Replace [$Main$] with [ Code]
This is truly the best thing I have seen for vb in a long time and I wish I found it earlier. No longer will you have to incorporate the vb6 runtimes making your setup files 10x bigger just because of the small minority of people that do not have them installed.
Enjoy everyone