使Inno Setup盲目地使用system32和/或syswow64



我需要一些关于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 文件夹中/在 syswow64 文件夹中完成。

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

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

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

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

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

正如我所说,我可以,并且已经编写了一个可以备份现有 calc.exe 文件的.bat文件,这些文件在 Win 64 的 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:InstallScriptsClasicCalculatorSetup
OutputBaseFilename=SetupClasicCalc
ArchitecturesAllowed= x86 x64
;ArchitecturesInstallIn64BitMode=
PrivilegesRequired=admin
MinVersion = 0,5.0
Compression=lzma
SolidCompression=yes
CreateUninstallRegKey=yes
UpdateUninstallLogAppName=yes
uninstallable=yes
SetupIconFile="C:InstallScriptsClasicCalculatorcalc-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:InstallScriptsClasicCalculatorWindowsSysWOW64*.*"; 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}windowssystem32calc.exe"; DestDir: "{sd}windowssystem32W10CalcBak"; DestName: "Calc.exe"; Permissions: authusers-full; Flags: external; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and not IsWin64
;Source: "{sd}windowssystem32calc.exe"; DestDir: "{sd}windowssystem32W10CalcBak"; 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:InstallScriptsClasicCalculatorWindowsSysWOW64*.*"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and IsWin64
Source: "C:InstallScriptsClasicCalculatorWindowsSystem32*.*"; DestDir: "{sys}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64
Source: "C:InstallScriptsClasicCalculatorWindowsSysWOW64*.*"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and not IsWin64

;Source: "{win}system32en-UScalc.exe.mui"; DestDir: "{win}system32W10CalcBak"; 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%windowssystem32calc.exe"' + ' /save ' + '"' + '%systemdrive%windowssystem32calc.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%windowssystem32calc.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%windowssystem32calc.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%windowssysWOW64calc.exe"' + ' /save ' + '"' + '%systemdrive%windowssysWOW64calc.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%windowssysWOW64calc.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%windowssysWOW64calc.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%windowssysWOW64calc.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%windowssysWOW64calc.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 文件夹中。我尝试在第 1 行"备份目标"代码中运行"Beforeinstall"部分,现在它在"文件"部分的部分,我实际替换了 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上,而不是在网页等上,甚至不在具有" II"设置或安装等的系统上。

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

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

在这一点上,我有很多味精框行来帮助我查看它在做什么等。

当显示第一个消息框时,其中包含"已解决"路径信息,如下图所示,该信息设置为正确的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 文件夹中做事,但我不能,所以我只想问是否有人会看看代码,看看他们是否可以找到我做错了什么并解释我如何纠正它。

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

拉尔夫

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

致米尔泰尔,

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

到莫斯基托,

虽然不建议这样做,但您确实可以覆盖系统文件。您只需要获得所有权并授予自己对文件的完全控制权。我的项目通过调用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和Takeown.exe.exe的"调用"。如果我使用"ShellExec",系统仍然将我的system32调用重定向到syswow64。

我还必须对我的文件部分进行一些调整以完成这个项目的安装部分,主要是按照"Sourece"行的顺序,当我调用"ChangeCalcPerms"过程时,我从单一的"Star.Star"风格将我的"新"文件复制到system32和syswow64文件夹以及.mui文件的"en-US"子文件夹,为四个文件中的每一个使用单独的代码行我需要放在"系统"文件夹中。这是必需的,因为 BeforeInstall/AfterInstall 函数将在"Star.Star"类型的调用中为每个文件运行,这导致我的程序运行两次,这不是设计用来做的,它是否导致了问题。(试图在"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:InstallScriptsClasicCalculatorWindowsSysWOW64calc.exe"; DestDir: "{sys}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and (not IsWin64)
Source: "C:InstallScriptsClasicCalculatorWindowsSysWOW64en-UScalc.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:InstallScriptsClasicCalculatorWindowsSystem32calc.exe"; DestDir: "{sys}"; Permissions: authusers-full; Flags: 64bit createallsubdirs recursesubdirs overwritereadonly; BeforeInstall: ChangeCalcPerms; Check: IsWindows10 and IsWin64
Source: "C:InstallScriptsClasicCalculatorWindowsSystem32en-UScalc.exe.mui"; DestDir: "{sys}en-US"; Permissions: authusers-full; Flags: 64bit createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64
Source: "C:InstallScriptsClasicCalculatorWindowsSysWOW64calc.exe"; DestDir: "{syswow64}"; Permissions: authusers-full; Flags: createallsubdirs recursesubdirs overwritereadonly; Check: IsWindows10 and IsWin64
Source: "C:InstallScriptsClasicCalculatorWindowsSysWOW64en-UScalc.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 system32calc.exe
CommandLine := '"' + '%systemdrive%windowssystem32calc.exe"' + ' /save ' + '"' + '%systemdrive%windowssystem32calc.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%windowssystem32calc.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%windowssystem32calc.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%windowssystem32calc.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%windowssystem32calc.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 syswow64calc.exe
CommandLine := '"' + '%systemdrive%windowssysWOW64calc.exe"' + ' /save ' + '"' + '%systemdrive%windowssysWOW64calc.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%windowssysWOW64calc.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%windowssysWOW64calc.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%windowssysWOW64calc.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%windowssysWOW64calc.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;

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

下一步是让"卸载"部分正常工作。

再次感谢!!!所有试图提供帮助并做到了的人!

拉尔夫

相关内容

最新更新