【问题标题】:Make Inno Setup use system32 and/or syswow64 as directed blindly让 Inno Setup 按照指示盲目使用 system32 和/或 syswow64
【发布时间】:2018-05-10 23:35:11
【问题描述】:

我需要一些关于 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 位 vs 32 位)我花了一个多星期的时间试图让我的代码把东西放在我告诉它“盲目”的地方。许多论坛上的大量研究,包括这里,似乎都没有提供好的信息和清晰的例子来告诉我如何拥有我需要的控制权。我知道哪个文件是 32 位的,哪个是 64 位的,以及每个文件应该进入哪个文件夹。但是 Inno Setup,错误地认为它知道得更好。

我希望我可以关闭该功能并使其使用我在代码等中编写它们时选择的绝对路径,但我还没有找到一种方法来做到这一点,所以我问如何让 Inno Setup 放置东西我告诉它去哪里,而不是它认为应该去哪里。

无论我如何尝试,我能做的最好的就是让它正确备份我将要覆盖的文件在 system32 和 syswow64 文件夹中。之后,“一切”总是在 syswow64 文件夹上完成,同样,无论我如何编码路径或使用什么标志,例如 64 位等。

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

这个特定代码要做的是将 Windows 10 计算器替换为我更喜欢的 Windows 7 版本。而且我想使用 Inno Setup,以便我可以让“卸载程序”将其全部放回。我知道其他人已经编写了代码来执行此操作,并且我可以从受信任的来源访问这些程序,我确信这些程序不会冒充“好”的“邪恶”,但在我的企业环境中,我不能冒险和我可以确定这样的代码没有恶意的唯一 100000% 方法是自己编写。另外,正如我所说,它提供了一次学习多种技术的绝佳机会。

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

我的代码发布在下面。在其中,您可以看到许多注释行,它们显示了我在需要时尝试放入路径的不同方式。您还将看到,我试图不需要在调用 ICACLS.exe 和 Takeown.exe 时嵌入 .bat 文件以进行权限控制,并且我正在使用(可能是错误的)“Beforinstall”选项来备份权限然后在目标文件上进行更改,以便我可以覆盖它等。我还试图避免在“运行”部分做任何事情,因为在这个项目中不需要这样做。我也有很多消息框要给我反馈,这些反馈将在最终版本中被注释掉,并且“/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

在下图中,您可以看到两个备份文件夹等.....Opps 愚蠢的认为不会让我放图片... WAAA,并说它会放一个链接。不是很聪明。我不知道为什么它会认为这会起作用,因为图片位于许多防火墙后面的本地 PC 上的本地高清上,而不是在网页等上,甚至不在具有“IIs”设置或安装等的系统上。 ...

然后它通过以下代码行中的“BeforeInstall:ChangeCalcPerms”选项转到“Proceedure”中名为“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 文件夹。

好的,没有图片,请参阅上面的 cmets。但请相信我,它在所有正确的位置显示“system32”,但它正在“syswow64”中完成所有工作。

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

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

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

拉尔夫

【问题讨论】:

  • 请为您的安装程序发布安装日志。对于您的屏幕截图,如果您不能自己托管文件,可以将文件上传到 imgur.com 等图片托管网站。
  • 您不能覆盖受保护的系统文件。打开具有管理员权限的 cmd 窗口。您现在位于 system32 文件夹中。输入ren calc.exe calc.off 你会得到一个错误。或move calc.exe C:\calc.exe
  • 我承认,我没有完整阅读您的问题(这个网站太长了)。但我的印象是您知道如何在常规部分处理 System32/SysWow64 问题,例如 [Files](使用 64bit 标志)。但是[Code] 部分有问题。在那里你需要使用EnableFsRedirection 函数:Inno Setup: Checking existence of a file in 32-bit System32 (Sysnative) folder

标签: inno-setup


【解决方案1】:

感谢 Mirtheil、Moskito 和 Martin 的帮助,

致米特尔,

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

致莫斯科,

虽然不推荐,但您确实可以覆盖系统文件。您只需要获得所有权并授予自己对文件的完全控制权。我的项目正是通过调用 Windows 操作系统中的 ICACLS.exe 和 TakeOwn.exe 等系统程序来实现的。这可以在 .bat 文件中完成。您必须具有管理员权限,但可以这样做。再次感谢您提供帮助。

致马丁·普里克里尔

谢谢!您对使用 EnableFsRedirection 功能的建议以及您发布的关于它的链接以及如何使用它,让我找到了解决方案。

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

  1. 在对“system32”文件/文件夹运行任何命令之前,我必须使用该功能禁用文件重定向。

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

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

我还必须对我的文件部分进行一些调整以完成该项目的安装部分,主要是按照“源”行的顺序以及当我调用“ChangeCalcPerms”程序并从单个“星号”开始时.Star”样式将我的“新”文件复制到 system32 和 syswow64 文件夹以及 .mui 文件的“en-US”子文件夹,以便为我需要放置的四个文件中的每一个使用单独的代码行“系统”文件夹。这是必需的,因为将在“Star.Star”类型的调用中为每个文件运行 BeforeInstall/AfterInstall 函数,这导致我的程序运行两次,而这不是设计的,并且会导致问题。 (尝试在“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;

我希望这可以帮助其他需要做这种事情的人。

下一步是让“卸载”部分工作。

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

拉尔夫

【讨论】:

  • 您可以使用{sd} 代替%systemdrive%{syswow64} 代替%systemdrive%\windows\sysWOW64
  • 感谢 Martin,我尝试使用 Inno Setup 常量,例如 {sys} 和 {sd},但禁用 FS 重定向的指令在我这样做时似乎失败了。仅当我使用 DOS 环境时。变量路径是否正确解析,当然,一旦我禁用了 FS 重定向。我对此没有任何解释,但这就是它在我的系统中的工作方式。我需要禁用 FS 重定向并更改为使用 DOS ENV Vars 作为我的路径,并且我必须使用 Exec 而不是 ShellExec,正如我在“修复”中所述。再次感谢你的帮助。拉尔夫
  • 我不建议使用{sys}。这确实不受禁用 FS 重定向的影响。但是{sd}{syswow64}应该没有问题。
猜你喜欢
  • 2018-05-29
  • 2014-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-06
  • 2011-05-05
  • 2015-05-10
相关资源
最近更新 更多