Inno setup 让Inno安装程序按照指示盲目使用system32和/或syswow64

Inno setup 让Inno安装程序按照指示盲目使用system32和/或syswow64,inno-setup,Inno Setup,我需要一些关于Inno设置的帮助 我的问题是让它盲目地将文件放在我想要的地方并执行操作 长话短说,除了一个例外,似乎我想在System32文件夹中做的每件事都会在SysWow64文件夹中结束。无论我如何称呼它,{sys}、{syswow64}、{sd}\windows\system32、{sd}\windows\syswow64,或者在我的代码部分、%systemdrive%\windows\system32、%systemdrive%\windows\syswow64,或者Expandcons

我需要一些关于Inno设置的帮助

我的问题是让它盲目地将文件放在我想要的地方并执行操作

长话短说,除了一个例外,似乎我想在System32文件夹中做的每件事都会在SysWow64文件夹中结束。无论我如何称呼它,{sys}、{syswow64}、{sd}\windows\system32、{sd}\windows\syswow64,或者在我的代码部分、%systemdrive%\windows\system32、%systemdrive%\windows\syswow64,或者Expandconstant'{sys}'\filename.exe等等,似乎都无关紧要。我甚至尝试过硬编码c:\windows\system32\filename.exe等等。在除一个之外的所有情况下,它都是在syswow64文件夹中完成的

我知道system32和syswow64文件夹之间的区别。64位对32位我花了一个多星期的时间试图让我的代码把东西放在我盲目告诉它的地方。在许多论坛上进行了大量的研究,包括在这里,似乎没有一个能提供好的信息和清晰的例子来告诉我如何控制我所需要的。我知道哪个文件是32位的,哪个是64位的,以及每个文件应该放在哪个文件夹中。但是Inno安装程序错误地认为它知道得更好

我希望我可以关闭该功能,并让它使用我在编写代码时选择的绝对路径等,但我还没有找到一种方法来做到这一点,所以我想问的是如何让Inno安装程序将东西放在我告诉它的地方,而不是它认为应该放在的地方

无论我如何尝试,我能做的最好的事情就是让它正确地备份我要在system32和syswow64文件夹中覆盖的文件。在此之后,无论我如何编码路径或使用什么标志(如64位等),所有操作都始终在syswow64文件夹上完成

我使用这个程序的目标有两个,主要的一个是学习如何使用Inno设置来控制文件/文件夹,根据需要更改权限,复制目标文件,然后恢复烫发等。我可以用.bat文件整天都这样做。但我想使用Inno安装程序,因为它可以帮助我完成项目的卸载部分,这将撤消我要做的更改,并将文件恢复到原始配置等。该项目的这一部分可能需要我回到这个论坛寻求更多帮助

这段特定代码将要做的是用我更喜欢的Windows7版本替换Windows10计算器。我想使用Inno安装程序,这样我就可以让卸载程序将其全部放回原处。我知道其他人已经编写了这样做的代码,我可以从可信的来源访问这些程序,我确信这些程序不会把邪恶伪装成善,但在我的企业环境中,我不能冒险,我唯一能确保这些代码没有邪恶的方法就是自己编写。另外,正如我所说,它提供了一个很好的机会,可以同时学习多种技术

正如我所说,我可以,并且已经编写了一个.bat文件,它可以备份现有的calc.exe文件,在64位版本的Win 10中,它同时存在于system32和syswow64文件夹中,这就是为什么我需要我的代码对这两个文件夹执行操作,并将它们替换为相应的Win 7版本等等,所以我知道这是可能的。我只需要知道如何在Inno设置中完成。由于使用路径语法,我的代码有几个不同的版本,它们都能够备份和覆盖syswow64中的calc.exe文件,但在64位Win 10操作系统上不能备份和覆盖system32

我的代码贴在下面。在其中,您可以看到许多注释行,这些注释行显示了我在需要时尝试放置路径的不同方式。您还将看到,我正在尝试不需要在调用ICACLS.exe和Takeown.exe进行权限控制时嵌入.bat文件,并且我正在使用,可能不正确,使用Beforinstall选项备份并更改目标文件的权限,以便覆盖它等。我还尝试避免在run部分中执行任何操作,因为此项目中不需要这样做。我也有很多消息框给我反馈,这些消息框将在最终版本上被注释掉,/k将被更改为/c,或者,如果我可以让它工作,只需直接调用ICACLS.exe和Takeown.exe程序,而不是首先使用cmd.exe。我已经完成了这项工作,但为了在故障排除阶段获得更好的反馈,我使用了带有/k的cmd.exe方法。这段代码预计在Win 10 x64操作系统上运行99.99%的时间,但也必须能够正确处理在Win 10 x86操作系统上运行的代码。我在Win 10 x64 V1709上完成这个项目

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

[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={{C771AFC7-CC36-4749-962D-119AD2671213}
AppName=Clasic Calculator
AppVerName=Classic Calculator Win 7 Style
AppPublisher=ACollege
AppPublisherURL=www.Acollege.edu
AppSupportURL=www.Acollege.edu
AppUpdatesURL=www.Acollege.edu
CreateAppDir=no
OutputDir=C:\InstallScripts\ClasicCalculator\Setup
OutputBaseFilename=SetupClasicCalc
ArchitecturesAllowed= x86 x64
;ArchitecturesInstallIn64BitMode=
PrivilegesRequired=admin
MinVersion = 0,5.0
Compression=lzma
SolidCompression=yes
CreateUninstallRegKey=yes
UpdateUninstallLogAppName=yes
uninstallable=yes
SetupIconFile="C:\InstallScripts\ClasicCalculator\calc-1.ico"





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

[Dirs]
;Win 10 Section


[Files]
;Windows 10 Section

;Testline for how is it running


;Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\*.*"; DestDir: "c:\TempTest"; Permissions: authusers-full; Flags:  createallsubdirs recursesubdirs overwritereadonly; Check: WhatIsIt


Source: "{syswow64}\calc.exe"; DestDir: "{syswow64}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; Check: IsWindows10 and not IsWin64

Source: "{sys}\calc.exe"; DestDir: "{sys}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: 64bit external; Check: IsWindows10 and IsWin64


;Source: "{sd}\windows\system32\calc.exe"; DestDir: "{sd}\windows\system32\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and not IsWin64

;Source: "{sd}\windows\system32\calc.exe"; DestDir: "{sd}\windows\system32\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: 64bit external; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and IsWin64

Source: "{syswow64}\calc.exe"; DestDir: "{syswow64}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; Check: IsWindows10 and IsWin64

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\*.*"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and IsWin64

Source: "C:\InstallScripts\ClasicCalculator\Windows\System32\*.*"; DestDir: "{sys}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\*.*"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and not IsWin64


;Source: "{win}\system32\en-US\calc.exe.mui"; DestDir: "{win}\system32\W10CalcBak"; DestName: "calc.exe.mui"; Permissions: authusers-full; Flags: external; Check: IsWindows10



[Registry]

[INI]

[Run]

[Code]

Function WhatIsIt(): Boolean;

begin

    if Is64BitInstallMode then

    begin  

      MsgBox('Installing in 64-bit mode', mbInformation, MB_OK)

    end

    else

    begin

      MsgBox('Installing in 32-bit mode', mbInformation, MB_OK);

    end;

    if IsWin64 then

    begin

      MsgBox('This is 64bit system', mbInformation, MB_OK)

      MsgBox('(PF64)-bit program files reside in: ' + ExpandConstant('{pf64}'), mbInformation, MB_OK);

      MsgBox('(PF32)-bit program files reside in: ' + ExpandConstant('{pf32}'), mbInformation, MB_OK);

      MsgBox('(PF) program files reside in: ' + ExpandConstant('{pf}'), mbInformation, MB_OK);

      MsgBox('(SYS) program files reside in: ' + ExpandConstant('{sys}'), mbInformation, MB_OK);

      MsgBox('(SYS64) program files reside in: ' + ExpandConstant('{syswow64}'), mbInformation, MB_OK);

      MsgBox('(SYS32) program files reside in: ' + ExpandConstant('{syswow64}'), mbInformation, MB_OK);

    end

    else

    begin

      MsgBox('This is NOT 64bit system', mbInformation, MB_OK)

      MsgBox('32-bit program files reside in: ' + ExpandConstant('{pf32}'), mbInformation, MB_OK);

     end;

    Exit


end;



Procedure ChangeCalcPerms();

var 
  CommandLine: String;
  ResultCode: Integer;

begin

  CommandLine := '"' + ExpandConstant('{sys}') + '\calc.exe"' + ' /save ' + '"' + ExpandConstant('{sys}') + '\calc.perms"'

  (*CommandLine := '"' + '%systemdrive%\windows\system32\calc.exe"' + ' /save ' + '"' + '%systemdrive%\windows\system32\calc.perms"'*)

  MsgBox('System 32 Backup Comandline is: ' + CommandLine, mbInformation, MB_OK);

  shellExec('','CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('ICACLS.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('System 32 Backup Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  CommandLine := '/F "' + ExpandConstant('{sys}') + '\calc.exe"' + ' /A'

  (*CommandLine := '/F "' + '%systemdrive%\windows\system32\calc.exe"' + ' /A'*)

  MsgBox('System 32 Make Owner Admin Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + 'Takeown.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'Takeown.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('Takeown.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('System 32 Make Owner Admin Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  CommandLine := '"' + ExpandConstant('{sys}') + '\calc.exe"' + ' /grant Administrators:f'

  (*CommandLine := '"' + '%systemdrive%\windows\system32\calc.exe"' + ' /grant Administrators:f'*)

  MsgBox('System 32 Give Admin Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('ICACLS.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('System 32 Give Admin Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  CommandLine := '"' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /save ' + '"' + '%systemdrive%\windows\sysWOW64\calc.perms"'

  MsgBox('Syswow 64 Backup Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('ICACLS.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('Syswow 64 Backup Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  CommandLine := '/F "' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /A'

  MsgBox('Syswow 64 Make Owner Admin Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + 'Takeown.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'Takeown.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('Takeown.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('Syswow 64 Make Owner Admin Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  CommandLine := '"' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /grant Administrators:f'

  MsgBox('Syswow 64 Give Admin Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('ICACLS.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('Syswow 64 Give Admin Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  CommandLine := '"' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /grant System:f'

  MsgBox('Syswow 64 Give System Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('ICACLS.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('Syswow 64 Give System Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  (*SECDeleteSYSWOW*)

  CommandLine := 'Del "' + '%systemdrive%\windows\sysWOW64\calc.exe"'

  MsgBox('Syswow 64 Del Calc.exe Comandline is: ' + CommandLine, mbInformation, MB_OK);

  ShellExec('','CMD.exe', '/k ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  (*Exec('CMD.exe', '/k ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  (*Exec('ICACLS.exe', CommandLine, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)*)

  MsgBox('Syswow 64 Del Calc.exe Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);


end;



function IsX64: Boolean;
begin
  Result := Is64BitInstallMode and (ProcessorArchitecture = paX64);

  (*MsgBox('IsWindows64 Result is: ' + inttostr(Integer(Result)), mbInformation, MB_OK)*)

end;


function IsIA64: Boolean;
begin
  Result := Is64BitInstallMode and (ProcessorArchitecture = paIA64);
end;

function IsOtherArch: Boolean;
begin
  Result := not IsX64 and not IsIA64;
end;


function IsWindowsXP: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);
  Result := Version.NTPlatform and (Version.Major = 5) and (Version.Minor = 1);
end;


function IsWindowsVista: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);

  Result := Version.NTPlatform and (Version.Major= 6) and (Version.Minor = 0);

end;

function IsWindows7: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);

  Result := Version.NTPlatform and (Version.Major = 6) and (Version.Minor = 1);

end;

function IsWindows10: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin

  GetWindowsVersionEx(Version);

  Result := Version.NTPlatform and (Version.Major= 10) and (Version.Minor = 0);

  (*MsgBox('IsWindows10 Result is: ' + inttostr(Integer(Result)), mbInformation, MB_OK)*)

end;

function IsWindowsVista_or_7: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);

  Result := Version.NTPlatform and (Version.Major = 6) and ((Version.Minor = 1) or (Version.Minor = 0));

end;

function IsWindowsVista_or_7_or_8: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);

  Result := Version.NTPlatform and (Version.Major = 6) and ((Version.Minor = 2) or (Version.Minor = 1) or (Version.Minor = 0));

end;


function IsWindows8: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);

  Result := Version.NTPlatform and (Version.Major = 6) and (Version.Minor = 2);

end;
不知何故,在文件部分的前3行中,我能够让程序正确地创建一个名为W10CalcBak的子文件夹,并将正确的calc.exe文件复制到system32和syswow64文件夹中。但在那之后,一切似乎都只发生在syswow64文件夹上。我已尝试在安装前运行 在前三部分中,备份目标代码行,现在在文件部分中,我实际替换了calc.exe文件。结果都一样

当我运行当前编写的代码时,它将使用以下3行代码正确执行备份文件部分

Source: "{syswow64}\calc.exe"; DestDir: "{syswow64}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; Check: IsWindows10 and not IsWin64


Source: "{sys}\calc.exe"; DestDir: "{sys}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: 64bit external; Check: IsWindows10 and IsWin64

Source: "{syswow64}\calc.exe"; DestDir: "{syswow64}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; Check: IsWindows10 and IsWin64
在下图中,您可以看到两个备份文件夹等。。。。。奥普斯 愚蠢的想法不会让我贴照片。。。WAAA,并表示将加入一个链接。不是很聪明。我不知道为什么它会认为这会起作用,因为图片是在许多防火墙后面的本地PC上的本地HD上,而不是在网页等上,甚至不是安装了IIs的系统等

然后,它通过以下代码行中的BeforeInstall:ChangeCalcPerms选项转到过程中名为ChangeCalcPerms的第一行

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\*.*"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and IsWin64
在这一点上,我有许多msgbox行来帮助我了解它正在做什么等

显示第一个消息框时,其中包含解析的路径信息,如下图所示,该信息被设置为正确的system32而不是syswow64文件夹。单击“确定”后,将打开一个DOS窗口,并发出ICACLS.exe命令,下一张图片将显示DOS窗口中似乎使用了通往system32的正确路径,然后在我退出该DOS窗口后,结果消息框的第三张图片返回正确的成功代码0。但是calc.perms不在system32文件夹中,即使在我看到的所有内容中都显示了system32。而是在syswow64文件夹中。这就是我需要停止/控制的。我需要这一行在system32文件夹上工作,而不是在syswow64文件夹上工作

好的,没有图片,请参见上面的评论。但请相信我,它在所有正确的地方显示了system32,但它在syswow64中完成了所有工作

我正在编写和编译代码的Win 7系统的源文件保存在两个文件夹中,system32和syswow64,以及带有正确calc.exe.mui语言文件的en US子文件夹等。我知道哪个是64位版本,哪个是system32文件夹,哪个是32位版本。但最后,唯一复制到syswow64文件夹中的文件是32位版本,64位版本没有复制,可能是因为权限不允许复制,因为它们没有得到应有的设置,这是因为我需要使用它,并在需要时对system32文件夹执行操作等问题

我将展示更多的图片,展示它如何正确解析路径,但似乎只在syswow64文件夹中执行操作,但我不能,所以我想问是否有人可以查看代码,看看他们是否可以找到我做错了什么,并解释我如何纠正它

首先非常感谢所有试图帮助我的人


拉尔夫

感谢米尔泰尔、莫斯基托和马丁的帮助

对米瑟尔来说

谢谢你关于如何发布我的图片的建议。由于Martin的建议给出了答案,我不认为我需要发布屏幕截图,但再次感谢您的想法

到莫斯基托

虽然不建议这样做,但确实可以覆盖系统文件。您只需取得所有权并授予自己对该文件的完全控制权。我的项目正是通过调用Windows操作系统中的系统程序(如ICACLS.exe和TakeOwn.exe)来实现这一点的。这可以在.bat文件中完成。你必须有管理员权限,但这是可以做到的。再次感谢你的帮助

致Martin Prikryl

谢谢大家!!您关于使用EnableFsRedirection函数的建议,以及您发布的关于它的链接和如何使用它的建议,让我找到了一个解决方案

解决方案需要对我的代码进行3次更改

在对system32文件/文件夹运行任何命令之前,我必须使用该函数禁用文件重定向

我必须将路径代码从使用内置Inno设置常量{sys}和{syswow64}更改为使用Windows/DOS环境变量%systemdrive%获取基本驱动器号,然后使用\Windows\system32完成路径。如果我使用{sys}常量,它仍然会将对system32的调用重定向到syswow64

我不得不重新使用Exec函数而不是ShellExec函数来执行对ICACLS.exe和Takeown.exe的调用。如果我使用ShellExec,系统仍然会将我的system32调用重定向到syswow64

我还必须对我的文件部分进行一些调整,以完成此项目的安装部分,主要是按照Sourece行的顺序,当我调用ChangeCalcPerms过程时,我从将新文件复制到system32和syswow64文件夹以及.mui文件的en-US子文件夹的单星.Star样式,改为对需要放置在系统文件夹中的四个文件中的每一个使用单独的代码行。这是必需的,因为将为每个fi运行安装前/安装后功能 这导致我的过程运行了两次,这不是它设计的,而是它造成了问题。试图在Star.Star中使用*符号,但它似乎有特殊的含义,并且弄乱了回复的外观

要完成此项目的安装部分,我需要做的最后一件事是从Win 7中获取新的calc.exe文件,我使用该文件替换Win 10版本,并恢复对其进行保护的原始权限。我计划添加一个新的过程,我将使用AfterInstall选项调用它,并将它放在“我的文件”部分的最后一行代码中

一旦我添加了最后一部分并对其进行了测试,我将删除所有消息框,项目的安装部分就应该完成了

在下一部分的答案中,我将根据您的帮助发布我的修复程序,以便为那些可能了解如何进行此类编码的人提供一个工作示例

我将在我的过程中的消息框等中留下,并将简单地告诉那些希望使用此代码的人,记住将它们注释掉,并在代码的Exec部分将/k更改为/c,以便代码在没有用户交互的情况下运行

“我的更正文件”部分

[Files]

; This section backs up the calc.exe files

; This line is for x86 systems only
Source: "{sys}\calc.exe"; DestDir: "{sys}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; Check: IsWindows10 and (not IsWin64)

; The next two lines are for x64 systems
Source: "{sys}\calc.exe"; DestDir: "{sys}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: 64bit external; Check: IsWindows10 and IsWin64

Source: "{syswow64}\calc.exe"; DestDir: "{syswow64}\W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; Check: IsWindows10 and IsWin64


; This section modifies the permisions and then deletes the calc.exe files then replaces them

; Next two lines are for x86 systems only

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\calc.exe"; DestDir: "{sys}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and (not IsWin64)

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\en-US\calc.exe.mui"; DestDir: "{sys}\en-US"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and (not IsWin64)

; Next four lines are for x64 systems only

Source: "C:\InstallScripts\ClasicCalculator\Windows\System32\calc.exe"; DestDir: "{sys}"; Permissions: authusers-full; Flags: 64bit createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and IsWin64

Source: "C:\InstallScripts\ClasicCalculator\Windows\System32\en-US\calc.exe.mui"; DestDir: "{sys}\en-US"; Permissions: authusers-full; Flags: 64bit createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\calc.exe"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64

Source: "C:\InstallScripts\ClasicCalculator\Windows\SysWOW64\en-US\calc.exe.mui"; DestDir: "{syswow64}\en-US"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64
下面是我的代码部分中更正的过程

[Code]

Procedure ChangeCalcPerms();

var
  OldState: Boolean;
  NewState: Boolean;
  CommandLine: String;
  ResultCode: Integer;

begin

  // Test to see if x64 system, if so disable FS Redirection..

  if IsWin64 then

  begin

  Msgbox('The system is x64, turning off the FS Redirection',mbInformation, MB_OK);

  //Turn of redirection

  OldState := EnableFsRedirection(False);

  Msgbox('The system is x64, turning off the FS Redirection, OldState = ' + inttostr(Integer(OldState)) ,mbInformation, MB_OK);

  end;

  // Start of x64 and x86 as both have system32 folder

  // Backup perms for system32\calc.exe

CommandLine := '"' + '%systemdrive%\windows\system32\calc.exe"' + ' /save ' + '"' + '%systemdrive%\windows\system32\calc.perms"'

  MsgBox('System 32 Backup Comandline is: ' + CommandLine, mbInformation, MB_OK);

 Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  MsgBox('System 32 Backup Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

 // Change Owner to Administrators

  CommandLine := '/F "' + '%systemdrive%\windows\system32\calc.exe"' + ' /A'

  MsgBox('System 32 Make Owner Admin Comandline is: ' + CommandLine, mbInformation, MB_OK);

  Exec('CMD.exe', '/k ' + 'Takeown.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  MsgBox('System 32 Make Owner Admin Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

  // Grant Administrators full control

 CommandLine := '"' + '%systemdrive%\windows\system32\calc.exe"' + ' /grant Administrators:f'

  MsgBox('System 32 Give Admin Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

MsgBox('System 32 Give Admin Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

 // Grant System Full Control

CommandLine := '"' + '%systemdrive%\windows\system32\calc.exe"' + ' /grant System:f'

  MsgBox('System 32 Give System Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

  MsgBox('System 32 Give System Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

 // Delete calc.exe in system32 folder

  CommandLine := 'Del "' + '%systemdrive%\windows\system32\calc.exe"'

  MsgBox('System32 Del Calc.exe Comandline is: ' + CommandLine, mbInformation, MB_OK);

 Exec('CMD.exe', '/k ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)


  // Start of x64 part *************

if IsWin64 then

  Begin

    // Backup perms for syswow64\calc.exe

    CommandLine := '"' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /save ' + '"' + '%systemdrive%\windows\sysWOW64\calc.perms"'

    MsgBox('Syswow 64 Backup Comandline is: ' + CommandLine, mbInformation, MB_OK);

 (Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

    MsgBox('Syswow 64 Backup Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

    // Change Owner to Administrators

    CommandLine := '/F "' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /A'

    MsgBox('Syswow 64 Make Owner Admin Comandline is: ' + CommandLine, mbInformation, MB_OK);

   Exec('CMD.exe', '/k ' + 'Takeown.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

   MsgBox('Syswow 64 Make Owner Admin Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

    // Grant Administrators full control

    CommandLine := '"' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /grant Administrators:f'

    MsgBox('Syswow 64 Give Admin Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

    Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

    MsgBox('Syswow 64 Give Admin Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

    // Grant System full control

    CommandLine := '"' + '%systemdrive%\windows\sysWOW64\calc.exe"' + ' /grant System:f'

    MsgBox('Syswow 64 Give System Full Perms Comandline is: ' + CommandLine, mbInformation, MB_OK);

 Exec('CMD.exe', '/k ' + 'ICACLS.exe ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

    MsgBox('Syswow 64 Give System Full Perms Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

    // Del calc.exe in Syswow64 folder

    CommandLine := 'Del "' + '%systemdrive%\windows\sysWOW64\calc.exe"'

    MsgBox('Syswow 64 Del Calc.exe Comandline is: ' + CommandLine, mbInformation, MB_OK);

    Exec('CMD.exe', '/k ' + commandline, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

    MsgBox('Syswow 64 Del Calc.exe Result is: ' + IntToStr(ResultCode), mbInformation, MB_OK);

    end;


  if IsWin64 then

  begin

  //Turn on redirection

  Msgbox('The system is x64, turning On the FS Redirection',mbInformation, MB_OK);

  NewState := EnableFsRedirection(OldState);

  Msgbox('The system is x64, turning On the FS Redirection, NewState = ' + inttostr(Integer(NewState)) ,mbInformation, MB_OK);

  end;


end;
我希望这能帮助其他需要做这类事情的人

下一步是让卸载部分工作

谢谢!!!!再次感谢所有试图帮助的人


Ralph

请发布安装程序的安装日志。对于您的屏幕截图,如果您不能自己托管,您可以将文件上载到imgur.com之类的图像主机。您不能覆盖受保护的系统文件。打开具有管理员权限的cmd窗口。您现在位于system32文件夹中。键入ren calc.exe calc.off您将得到一个错误。或者移动calc.exe C:\calc.exe我承认,我没有阅读你的全部问题,这个网站太长了。但我的印象是,您知道如何在常规部分处理System32/SysWow64问题,比如使用64位标志的[Files]。但您在[代码]部分有问题。您需要使用EnableFsRedirection函数:。您可以使用{sd}而不是%systemdrive%,也可以使用{syswow64}而不是%systemdrive%\windows\syswow64。感谢Martin,我尝试使用Inno设置常量,如{sys}和{sd},但禁用FS重定向的指令似乎失败了。只有当我使用DOS环境时。当然,一旦我禁用FS重定向,路径是否正确解析。我对此没有解释,但这就是它在我的系统中的工作方式。我需要禁用FS重定向并更改为对路径使用DOS ENV VAR,并且我必须使用Exec而不是ShellExec,正如我在修复中所述。再次感谢你的帮助。RalphI不建议使用{sys}。禁用FS重定向确实不会影响这一点。但是{sd}和{syswow64}应该没有任何问题。