Windows installer 用于安装python的Inno安装程序代码
我有一个inno设置代码,用于安装python。它工作正常,我得到了setup.exe文件,其中的setup文件包含python。但是,当我尝试使用该安装文件安装python时,它不起作用。这是因为安装文件正在查找文件部分中指定的python文件,如果是,我如何更改代码,以便使用setup.exe中的python。此外,每次安装该设置时,安装程序都会创建一个默认应用程序。我尝试了属性DisableDirPage=yes,但它不起作用。有谁能提出一些解决办法吗Windows installer 用于安装python的Inno安装程序代码,windows-installer,inno-setup,Windows Installer,Inno Setup,我有一个inno设置代码,用于安装python。它工作正常,我得到了setup.exe文件,其中的setup文件包含python。但是,当我尝试使用该安装文件安装python时,它不起作用。这是因为安装文件正在查找文件部分中指定的python文件,如果是,我如何更改代码,以便使用setup.exe中的python。此外,每次安装该设置时,安装程序都会创建一个默认应用程序。我尝试了属性DisableDirPage=yes,但它不起作用。有谁能提出一些解决办法吗 #defi
#define MyAppName "My Program"
#define MyAppVersion "1.5"
[Setup]
AppId={{BD59E856-F194-4E05-A93B-89089F3E3E9D}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
;AppPublisher={#MyAppPublisher}
;AppPublisherURL={#MyAppURL}
;AppSupportURL={#MyAppURL}
;AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
DisableDirPage=yes
[Files]
Source: "H:\python-2.7.5.msi"; DestDir: "{app}"; Flags: ignoreversion
[code]
#define MinJRE "1.6"
#define WebJRE "H:\python-2.7.5.msi"
function InitializeSetup(): Boolean;
var
ErrorCode: Integer;
PythonInstalled : Boolean;
Result1 : Boolean;
begin
PythonInstalled := RegKeyExists(HKLM,'SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath');
if PythonInstalled then
begin
MsgBox('installed', mbInformation, MB_OK);
end
else
begin
Result1 := MsgBox('2222222222222222This tool requires python Runtime Environment to run. Do you want to install it now?',
mbConfirmation, MB_YESNO) = idYes;
if Result1 = false then
begin
Result:=false;
end
else
begin
MsgBox('not installed', mbInformation, MB_OK);
Result:=true;
ShellExec('',
'{#WebJRE}',
'','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
end;
end;
end;
正如特拉玛所说,对脚本做了一些更改。在我这边工作得很好,更改了文件节条目并使用Exec而不是SHELLEEXEC 将python-2.7.5.amd64.msi替换为python-2.7.5.msi 并将D:\替换为H:\
#define MyAppName "My Program"
#define MyAppVersion "1.5"
[Setup]
AppId={{BD59E856-F194-4E05-A93B-89089F3E3E9D}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
DisableDirPage=yes
[Files]
Source: "D:\python-2.7.5.amd64.msi"; Flags: dontcopy
[code]
#define MinJRE "1.6"
function InitializeSetup: Boolean;
var
ErrorCode: Integer;
PythonInstalled: Boolean;
Result1: Boolean;
WebJRE: string;
begin
PythonInstalled := RegKeyExists(HKLM, 'SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath');
if PythonInstalled then
begin
MsgBox('installed', mbInformation, MB_OK);
end
else
begin
Result1 := MsgBox('This tool requires python Runtime Environment to run. Do you want to install it now ?', mbConfirmation, MB_YESNO) = IDYES;
if not Result1 then
begin
Result := False;
end
else
begin
MsgBox('not installed', mbInformation, MB_OK);
Result := True;
ExtractTemporaryFile('python-2.7.5.amd64.msi')
WebJRE:='"'+Expandconstant('{tmp}\python-2.7.5.amd64.msi')+'"'
Exec('cmd.exe ','/c'+WebJRE,'', SW_HIDE,ewWaituntilterminated, Errorcode);
end;
end;
end;
您正在调用
ShellExec
并传递#WebJRE
常量,该常量位于H:
驱动器的某处。将[Files]
条目更改为Source:“H:\python-2.7.5.msi”;Flags:dontcopy
,因为我认为您不想将该安装程序复制到目标应用程序文件夹中。在调用ShellExec
之前的InitializeSetup
事件方法中,使用ExtractTemporaryFile('python-2.7.5.msi')
,然后从{tmp}\python-2.7.5.msi
路径执行它。您还应该改进代码格式并添加错误处理。@TLama我已进行了指定的更改并编译了代码。但现在,在执行安装程序时,它只会将文件复制到选定的文件夹,例如C:\Program files(x86)\My Program,其中包含python安装程序,ShellExec不工作。您能告诉我我的代码出了什么问题吗?我猜您在调用ShellExec
时没有使用ExpandConstant({tmp}\python-2.7.5.msi')
扩展常量。调用该函数时,必须扩展传递给该函数的路径。绝对不需要使用cmd.exe
。与ShellExec
做的事情非常相似。@TLama我喜欢你的编辑。是的,ShellExec也工作得很好。不使用cmd.exe,我们也可以这样做。我退出Exec+cmd.exe会更舒服。这就是我在这里使用的原因。非常感谢您的编辑和信息。