【问题标题】:What should be done to copy files from installed directory to another after installation complete using inno setup script?安装完成后使用 inno 安装脚本将文件从安装目录复制到另一个目录应该怎么做?
【发布时间】:2015-01-29 09:21:53
【问题描述】:

先告诉你我的目的。我有一些应用程序正在使用的动态链接库。对于客户要求,我需要将它们复制到 Windows 的 System32 目录中。但是我在做这件事时遇到了一些问题。

我之前已经检查过this 链接。但我不明白我会修改我的脚本以调用一个在安装后复制文件的函数。即何时、何地以及如何调用这样的函数。

她是我的剧本

#define MyAppName "ABC ToolS"
#define MyAppVersion "1.0"
#define MyAppPublisher "ABC Lab Ltd."
#define MyAppURL "ABC.com"
#define MyAppExeName "MyProg.exe"

[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={{399B836A-28F5-4741-A54F-09658DE3E407}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=C:\Users\user06\Desktop
OutputBaseFilename=A
SetupIconFile=C:\Users\user06\Desktop\Release\logo.ico
Compression=lzma
SolidCompression=yes

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

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

[Files]
Source: "C:\Program Files\Inno Setup 5\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\user06\Desktop\Release\A.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\user06\Desktop\Release\lib\A.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\user06\Desktop\Release\B.dll"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
; ADDED AS AN EXAMPLE
;If the DLL should be copied to System32 (on both 32 and 64 bit Windows versions)

Source: "C:\Users\user06\Desktop\Release\lib\A.dll"; DestDir: "{sys}"; Flags: sharedfile 

;If the DLL should be copied to System32 on 32 bit Windows and to SysWOW64 on 64 bit Windows - Do not use this constant unless you have a specific need to obtain the name of the actual directory in which 32-bit system files reside. Gratuitously using {syswow64} in places where {sys} will suffice may cause problems.

Source: "C:\Users\user06\Desktop\Release\lib\A.dll"; DestDir: "{syswow64}"; Flags: sharedfile 


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

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

;[PostIn]

请帮我修改我的脚本,以便我可以在安装后复制文件。此外,我还需要在卸载程序时删除它们。但我找不到任何卸载程序脚本。有人吗?

【问题讨论】:

  • 但是您要复制哪些文件以及从哪里复制?目标文件夹应该是什么?
  • @RobeN 您可以在我的脚本中看到我已将 A.dll 复制到 app 文件夹。安装后我想将 A.dll 从应用程序复制到 system32。
  • 如果您认为将 DLL 复制到 System32 中是正确的解决方案,那么您几乎肯定做错了什么。在 90 年代做这些事情是有原因的,但是(检查日历)它是 2015 年,这是一个属于操作系统的 system 目录,而不是你。
  • 所以只需指向DestDir: "{sys}"DestDir: "{syswow64}",但您应该另外设置Flags: sharedfile onlyifdoesntexist,特别是如果您的DLL 可以被其他软件使用或可能已经安装。有关详细信息,请参阅 Inno Setup 文档中的 Constants[Files] section
  • 这就是它的工作原理。您在计算机上编译安装程序,然后 DLL 文件已包含在 Setup.exe 中。运行后,DLL 文件将从 Setup.exe 提取到系统文件夹。 Source 在编译命令中指向将被编译到 Setup.exe 中的文件。你不使用Flags: external

标签: installation inno-setup


【解决方案1】:

你必须指向DestDir: "{sys}"(或DestDir: "{syswow64}"仅在特殊情况下)

在安装程序Compiling 之后,Source: 指向的所有文件将被集成并存储在Setup.exe 中。在安装过程中,Setup.exe 中的所有文件都将复制到脚本中描述为DestDir 的目标文件夹中。

例子:

[Files]
;If the DLL should be copied to System32 (on both 32 and 64 bit Windows versions)

Source: "C:\Users\user06\Desktop\Release\lib\A.dll"; DestDir: "{sys}"; Flags: sharedfile 

;If the DLL should be copied to System32 on 32 bit Windows 
;and to SysWOW64 on 64 bit Windows - Do not use this constant 
;unless you have a specific need to obtain the name of the actual 
;directory in which 32-bit system files reside. 
;Gratuitously using {syswow64} in places where {sys} will suffice 
;may cause problems.

Source: "C:\Users\user06\Desktop\Release\lib\A.dll"; DestDir: "{syswow64}"; Flags: sharedfile 

【讨论】:

  • 我尝试使用 Source: "D:\test.dll; DestDir: "{sys}"; Flags: sharedfile 但文件被复制到 syswow64 而不是 system32 文件夹。请帮助
  • 如果您在 32 位模式下运行安装程序(默认情况下),则 {sys} 将扩展为 syswow64。为了将{sys} 扩展为 C:\WINDOWS\SYSTEM,您必须在 64 位模式下运行安装程序。更多内容等你发现here
猜你喜欢
  • 2012-09-19
  • 2013-09-12
  • 2017-03-25
  • 1970-01-01
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多