我想用inno setup检测用户电脑是否安装了.net framework

我想用inno setup检测用户电脑是否安装了.net framework,如何通过.net framework的注册表信息来判别,但是它的信息写在了这个HKEY_LOCAL_MACHINE目录下,而访问这个HKEY_LOCAL_MACHINE需要管理员的权限才行。我本机测试(我的操作系统是xp,32位),不管是admin还是user,都可以访问得到里面的信息。我发送到64位的的win7系统的电脑测试,仍然可以访问,而我发送到除我之外的任何一台xp系统或win7(32位)系统的机子,均不能读取注册表里的信息。
请问各位如何解决?

我写的代码如下:

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "超级无敌大程序"
#define MyAppVersion "1.5"
#define MyAppPublisher "求知科技"
#define IncludeFramework true
#define IsExternal ""
#define MyAppURL "http://www.qiuzhi.com/"
#define MyAppExeName "EasyKao.exe"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{D6328262-08DA-47EA-8899-86850CF7D3B1}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=安装
OutputBaseFilename=setup
SetupIconFile=D:\打包测试\Setup.ico   
Compression=lzma
SolidCompression=yes
DisableReadyPage=yes
PrivilegesRequired=lowest



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

;生成快捷方式
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "D:\打包测试\x\*"; DestDir: "{app}"; Flags: ignoreversion
;{#IsExternal}; Check: NeedsFramework
Source: "D:\打包测试\x\data\*"; DestDir: "{app}\data"; Flags: ignoreversion
Source: "D:\打包测试\MyProg-x64.exe"; DestDir: "{app}"; DestName: "MyProg.exe"; Check: Is64BitInstallMode
Source: "D:\打包测试\MyProg.exe"; DestDir: "{app}"; Check: not Is64BitInstallMode
;#if IncludeFramework
;Source: "D:\打包测试\x\dotnetfx.exe"; DestDir: "{app}"; Flags: ignoreversion {#IsExternal}; Check: NeedsFramework
;#endif
;Source:"D:\打包测试\you.ico"; DestDir: "{app}";
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon; IconFilename: "{app}\you.ico"

;[Registry]
;Root:HKLM; Subkey: "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client\Install";Permissions: users-full

;上面的tasks要和【Tasks】的name名称一样,要一一对应

[Run]
;#if IncludeFramework
;Filename: {app}\dotnetfx.exe; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "Installing .NET Framework if needed"
;#endif
;Filename: {app}\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..."
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent ; 

;[UninstallRun]
;Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: "-q -machine -remgroup ""{#MyAppName}"""; Flags: skipifdoesntexist runhidden;

[Code]
function InitializeSetup(): Boolean;   
var sVersion: Cardinal;

begin
  //Log('InitializeSetup called');
  //Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
  //if Result = False then
  //  MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);

  if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client','Install',sVersion) then
  if sVersion=1 then
  begin
    //MsgBox('Your country: ' + IntToStr(sVersion),mbConfirmation, MB_OK);
      MsgBox('你的电脑安装了.net4.0', mbInformation,MB_OK);
     //Path := ExpandConstant('Setup\dotnetfx.exe');
     //Exec(Path, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
  end
  else
  //检测3.0
  begin
    if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5','Install',sVersion) then
    if sVersion=1 then
    begin
               MsgBox('你的电脑安装了.net3.5', mbInformation,MB_OK);
    end
    else 
    begin
     //检测3.0
     if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0','Install',sVersion) then
     if sVersion=1 then
    begin
               MsgBox('你的电脑安装了.net3.0', mbInformation,MB_OK);
    end
    else 
    begin
       //检测2.0
       if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0','Install',sVersion) then
       if sVersion=1 then
        begin
               MsgBox('你的电脑安装了.net2.0'+InttoStr(sVersion), mbInformation,MB_OK);
        end
       else
       begin
               MsgBox('你的电脑没有安装了.net2.0', mbError,MB_OK);
       end
    end
    end
  end
end;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值