C# Im使用inno安装程序检测是否安装了.net 4.0客户端,但它没有';工作不好

C# Im使用inno安装程序检测是否安装了.net 4.0客户端,但它没有';工作不好,c#,C#,当我安装程序时,它会检查是否安装了.net 4.0客户端 如果没有,那么应该安装它 问题是,如果我再次运行安装程序,安装文件将尝试再次安装.Net 4.0客户端,但这次它给了我修复或删除.Net 4.0客户端的选项 我不知道为什么在随后的尝试中它会再次尝试安装.Net 另一个问题是,在[Run]部分,我正在运行FFDS如何在静默模式下安装它如何检查它是否已安装,以便不再安装它 这是我的剧本: ; Script generated by the Inno Setup Script Wizard.

当我安装程序时,它会检查是否安装了.net 4.0客户端

如果没有,那么应该安装它

问题是,如果我再次运行安装程序,安装文件将尝试再次安装.Net 4.0客户端,但这次它给了我修复或删除.Net 4.0客户端的选项

我不知道为什么在随后的尝试中它会再次尝试安装.Net

另一个问题是,在[Run]部分,我正在运行FFDS如何在静默模式下安装它如何检查它是否已安装,以便不再安装它

这是我的剧本:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Lightnings Extractor"
#define MyAppVersion "Lightnings Extractor 1.0"
#define MyAppExeName "Lightnings Extractor.exe"
#define FfdshowExeName "

[_ISTool]
EnableISX=true


[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{E60E9193-B054-4026-98EA-5DAD45CE9B0B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=D:\Lightnings_Extractor Setup
OutputBaseFilename=LE_Setup
SetupIconFile=D:\MyWeatherStation-Images-And-Icons\Weather_Michmoret.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: D:\Lightnings_Extractor Setup\Lightnings Extractor InnoSetup Script\isxdl\isxdl.dll; Flags: dontcopy
Source: "D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\bin\Release\Lightnings Extractor.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\bin\Release\DirectShowLib-2005.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\bin\Release\unfreez_wrapper.dll"; DestDir: "{app}"; Flags: ignoreversion
Source:  "D:\Appz\ffdshow_rev4225_20120105_clsid.exe"; DestDir: "{app}"; Flags: ignoreversion 
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Messages]
WinVersionTooLowError=MyApp requires Windows NT4, Windows 98 or later.

[Icons]
Name: "{group}\{#MyAppName}"; 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
Filename: {app}\ffdshow_rev4225_20120105_clsid.exe; Parameters: /silent; StatusMsg: Installing ffdshow...

[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=5765d7a8-7722-4888-a970-ac39b33fd8ab&srcdisplaylang=en&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f7%2fB%2f6%2f7B629E05-399A-4A92-B5BC-484C74B5124B%2fdotNetFx40_Client_setup.exe';
  // local system for testing...    
  // dotnetRedistURL = 'http://192.168.1.1/dotnetfx.exe';

function InitializeSetup(): Boolean;

begin
  Result := true;
  dotNetNeeded := false;

  // Check for required netfx on windows xp installation
  if (not RegKeyExists(HKLM, 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0')) then begin
    dotNetNeeded := true;
    if (not IsAdminLoggedOn()) then begin
      MsgBox('MyApp needs the Microsoft .NET Framework to be installed by an Administrator', mbInformation, MB_OK);
      Result := false;
    end else begin
      memoDependenciesNeeded := memoDependenciesNeeded + '      .NET Framework' #13;
      dotnetRedistPath := ExpandConstant('{src}\dotnetfx.exe');
      if not FileExists(dotnetRedistPath) then begin
        dotnetRedistPath := ExpandConstant('{tmp}\dotnetfx.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

    hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));

    // don't try to init isxdl if it's not needed because it will error on < ie 3
    if downloadNeeded then begin

      isxdl_SetOption('label', 'Downloading Microsoft .NET Framework');
      isxdl_SetOption('description', 'MyApp needs to install the Microsoft .NET Framework. Please wait while Setup is downloading extra files to your computer.');
      if isxdl_DownloadFiles(hWnd) = 0 then Result := false;
    end;
    if (Result = true) and (dotNetNeeded = true) then begin
      if Exec(ExpandConstant(dotnetRedistPath), '', '', 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;

function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
  s: string;

begin
  if memoDependenciesNeeded <> '' then s := s + 'Dependencies to install:' + NewLine + memoDependenciesNeeded + NewLine;
  s := s + MemoDirInfo + NewLine + NewLine;

  Result := s
end;

//testing

function InitializeSetups(): Boolean;

begin
  Result := true;
  dotNetNeeded := false;

  // Check for required netfx on windows xp installation
  if (not RegKeyExists(HKLM, 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4')) then begin
    dotNetNeeded := true;
    if (not IsAdminLoggedOn()) then begin
      MsgBox('MyApp needs the Microsoft .NET Framework to be installed by an Administrator', mbInformation, MB_OK);
      Result := false;
    end else begin
      memoDependenciesNeeded := memoDependenciesNeeded + '      .NET Framework' #13;
      dotnetRedistPath := ExpandConstant('{src}\dotnetfx.exe');
      if not FileExists(dotnetRedistPath) then begin
        dotnetRedistPath := ExpandConstant('{tmp}\dotnetfx.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 NextButtonClicks(CurPage: Integer): Boolean;
var
  hWnd: Integer;
  ResultCode: Integer;

begin
  Result := true;

  if CurPage = wpReady then begin

    hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));

    // don't try to init isxdl if it's not needed because it will error on < ie 3
    if downloadNeeded then begin

      isxdl_SetOption('label', 'Downloading Microsoft .NET Framework');
      isxdl_SetOption('description', 'MyApp needs to install the Microsoft .NET Framework. Please wait while Setup is downloading extra files to your computer.');
      if isxdl_DownloadFiles(hWnd) = 0 then Result := false;
    end;
    if (Result = true) and (dotNetNeeded = true) then begin
      if Exec(ExpandConstant(dotnetRedistPath), '', '', 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;

function UpdateReadyMemos(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
  s: string;

begin
  if memoDependenciesNeeded <> '' then s := s + 'Dependencies to install:' + NewLine + memoDependenciesNeeded + NewLine;
  s := s + MemoDirInfo + NewLine + NewLine;

  Result := s
end;
;由Inno安装脚本向导生成的脚本。
; 有关创建INNO安装脚本文件的详细信息,请参阅文档!
#定义MyAppName“Lightings提取器”
#定义MyAppVersion“Lightings提取器1.0”
#定义MyAppExeName“Lightings提取器.exe”
#定义FfdshowExeName“
[u ISTool]
EnableISX=true
[设置]
;注意:AppId的值唯一标识此应用程序。
;不要在其他应用程序的安装程序中使用相同的AppId值。
|(要生成新的GUID,请单击工具|在IDE中生成GUID。)
AppId={E60E9193-B054-4026-98EA-5DAD45CE9B0B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={{#MyAppName}{#MyAppVersion}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=D:\Lightings\u提取器设置
OutputBaseFilename=LE\u设置
SetupIconFile=D:\MyWeatherStation图像和图标\Weather\u Michmoret.ico
压缩=lzma
SolidCompression=是
PrivilegesRequired=admin
[语文]
名称:“英语”消息文件:“编译器:Default.isl”
[任务]
名称:“desktopicon”说明:“{cm:CreateDesktopIcon}”;组说明:“{cm:AdditionalIcons}”;标志:未选中
[档案]
来源:D:\Lightings\U提取器安装程序\Lightings提取器InnoSetup脚本\isxdl\isxdl.dll;标志:dontcopy
来源:“D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\bin\Release\lightings Extractor.exe”;DestDir:{app};标志:ignoreversion
来源:“D:\C-Sharp\Extracting\u Frames\Extracting\u Frames\Extracting\u Frames\bin\Release\DirectShowLib-2005.dll”;DestDir:{app};标志:ignoreversion
来源:“D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\bin\Release\unfreez_wrapper.dll”;DestDir:{app};标志:ignoreversion
来源:“D:\Appz\ffdshow_rev4225_20120105_clsid.exe”DestDir:“{app}”标志:ignoreversion
;注意:不要在任何共享系统文件上使用“Flags:ignoreversion”
[留言]
WinVersionTooLowError=MyApp需要Windows NT4、Windows 98或更高版本。
[图标]
名称:{group}{{MyAppName};文件名:{app}{{MyAppExeName}”
名称:{group}{cm:UninstallProgram,{MyAppName}};文件名:{uninstallexe}
名称:{commondesktop}{#MyAppName};文件名:{app}{#MyAppExeName};任务:桌面图标
[运行]
文件名:“{app}\{MyAppExeName}”说明:{cm:LaunchProgram,{{StringChange(MyAppName,&',&',&&')}}”标志:nowait postinstall skipifsilent
文件名:{app}\ffdshow_rev4225_20120105_clsid.exe;参数:/silent;StatusMsg:安装ffdshow。。。
[守则]
变量
dotnetRedistPath:字符串;
下载需要:布尔;
dotNetNeeded:布尔值;
MemoDependenciesRequired:字符串;
程序isxdl_AddFile(URL,文件名:PChar);
“外部”isxdl_AddFile@files:isxdl.dll stdcall';
函数isxdl_DownloadFiles(hWnd:Integer):Integer;
“外部”isxdl_DownloadFiles@files:isxdl.dll stdcall';
函数isxdl_SetOption(选项,值:PChar):整数;
“外部”isxdl_SetOption@files:isxdl.dll stdcall';
常数
DotnetRedisturhttp://www.microsoft.com/downloads/info.aspx?na=41&srcfamilyid=5765d7a8-7722-4888-a970-ac39b33fd8ab&srcdisplaylang=en&u=http%3a%2f%2f下载。microsoft.com%2f下载%2f7%2fB%2f6%2f7B629E05-399A-4A92-B5BC-484C74B5124B%2fdotNetFx40_客户端_setup.exe;
//本地测试系统。。。
//DotnetRedisturhttp://192.168.1.1/dotnetfx.exe';
函数InitializeSetup():Boolean;
开始
结果:=真;
dotNetNeeded:=false;
//在windows xp安装中检查所需的netfx
如果(不存在注册表项(HKLM,'HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0')),则开始
dotNetNeeded:=true;
如果(不是isAdminLogedon()),则开始
MsgBox('MyApp需要管理员安装Microsoft.NET Framework',mbInformation,MB_OK);
结果:=假;
结束,否则开始
MemoDependenciesRequired:=MemoDependenciesRequired+“.NET Framework”#13;
dotnetRedistPath:=ExpandConstant('{src}\dotnetfx.exe');
如果文件不存在(dotnetRedistPath),则开始
dotnetRedistPath:=ExpandConstant('{tmp}\dotnetfx.exe');
如果文件不存在(dotnetRedistPath),则开始
isxdl_AddFile(dotnetredistur、dotnetRedistPath);
DownloadRequired:=真;
结束;
结束;
SetIniString('install','dotnetRedist','dotnetRedistPath',ExpandConstant('{tmp}\dep.ini');
结束;
结束;
结束;
函数NextButtonClick(CurPage:Integer):布尔值;
变量
hWnd:整数;
结果代码:整数;
开始
结果:=真;
如果CurPage=wpReady,则开始
hWnd:=stroint(ExpandConstant({wizardhwnd}');
//如果不需要,不要尝试初始化isxdl,因为它将在[Files]
;Redistributables
Source: Redistributables\*; DestDir: {tmp}; Flags: ignoreversion deleteafterinstall


[Code]
var dotNET40Missing: Boolean; // Is the .NET 4.0 Framework missing entirely?

function InitializeSetup(): Boolean;
begin
    // Test the presence of .NET 4.0
    if (not(RegKeyExists(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4'))) then
        dotNET40Missing := True;

    Result := True;
end;

function ShouldInstalldotNET40(): Boolean;
begin
    Result := dotNET40Missing;
end;

[Run]
Filename: {tmp}\.NET 4.0.exe; Description: Install Microsoft .Net Framework 4.0;    Parameters: /q /noreboot; Flags: skipifdoesntexist; Check: ShouldInstalldotNET40
if (not RegKeyExists(HKLM, 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0')
if (not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0')