I try to run a python script during a setup generate by InnoSetup , but nothing works. Neither the Run section or Exec in code section Result code differ depending the way I call it.
Of course I install Python during the setup if it's not already present. Here is the test code Inno
[Setup]
AppName=PyPy_client
AppVersion=0.1
DefaultDirName={pf}\DeployPyPy
UninstallDisplayIcon={app}\test.py
Compression = zip/1
OutputDir=deploy
SetupLogging = yes
UsePreviousGroup=False
DisableProgramGroupPage=yes
PrivilegesRequired = admin
[Files]
Source: "D:\Dev\deploy_python\python-3.3.2.msi"; DestDir: "{app}\deploy"; Flags: ignoreversion
Source: "D:\Dev\deploy_python\test.py"; DestDir: "{app}"; Flags: ignoreversion
[Run]
Filename: "msiexec"; Parameters: "/i ""{app}\deploy\python-3.3.2.msi"" /qb! ALLUSER=1 ADDLOCAL=ALL"; WorkingDir: "{app}\deploy"; Flags: 32bit; Check: python_is_installed
Filename: "cmd.exe"; Parameters: "/c{code:GetPythonPath}\python.exe {app}\test.py"; WorkingDir: "{app}"; Flags: waituntilterminated
[Code]
function python_is_installed() : Boolean;
var
key : string;
begin
//check registry
key := 'software\Python\PythonCore\3.3\InstallPath'
Result := not RegValueExists(HKEY_LOCAL_MACHINE,Key,'');
end;
function GetPythonPath(Param : String) : String;
var dir, key : String;
begin
dir := '';
key := 'software\Python\PythonCore\3.3\InstallPath'
RegQueryStringValue(HKEY_LOCAL_MACHINE,key,'',dir);
Result := dir
end;
procedure DeinitializeSetup();
var
ResultCode: integer;
begin
if Exec('cmd.exe', ExpandConstant('/c' +GetPythonPath('')+ '\python.exe {app}\test.py'), '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
Log(intTostr(Resultcode));
end;
I Try to use directly python.exe in Run section and in code:Exec but no way.
And of course if I type test.py in windows command line it works , and the cmd.exe /cC:\python33\python.exe C:\app\test.py also
Somebody already succes using python script with innosetup ?
The purpose of this is not to distribute py file of an app but using python script during the installation process to make some stuff.
Now I m' using CXfreeeze to make an exe of the scripts but I prefer to keep only the python script and not exe (for automatisation purpose)
for information python test script is just :
import ctypes
def msgbox(message,title):
ctypes.windll.user32.MessageBoxW(0, message, title, 0)
def debug() :
msgbox('test','test test')
debug()
EDIT *
As @Tlama suggest I have tried to use the command in [Run] using OriginalUser instead of the Admin mode setted by inno (I m using the PrivilegesRequired = admin ) but it doesn't Work.
And as I install python for all users with the command line ALLUSERS=1 existing users (or admin) can run python scripts.
I also try to modify the WorkingDir in [Run] and in CODE:Exec but all tentatives give me the same ResultCode "2"
Filename: "cmd.exe"; Parameters: "/c{code:GetPythonPath}\python.exe {app}\test.py"; WorkingDir: "{app}"; Flags: waituntilterminated
Filename: "cmd.exe"; Parameters: "/c{code:GetPythonPath}\python.exe {app}\test.py"; WorkingDir: "{code:GetPythonPath}"; Flags: waituntilterminated
Filename: "python.exe"; Parameters: "{app}\test.py"; WorkingDir: "{code:GetPythonPath}"; Flags: waituntilterminated
Filename: "python.exe"; Parameters: "{app}\test.py"; WorkingDir: "{app}"; Flags: waituntilterminated
in CODE :
Log('Start pypy 1');
Exec('cmd.exe', ExpandConstant('/c' +GetPythonPath('')+ '\python.exe {app}\test.py'), GetPythonPath(''), SW_SHOW, ewWaitUntilTerminated, ResultCode);
Log(intToStr(Resultcode));
Log('Start pypy 2');
Exec(GetPythonPath('')+ '\python.exe', ExpandConstant('{app}\test.py'), GetPythonPath(''), SW_SHOW, ewWaitUntilTerminated, ResultCode);
Log(intToStr(Resultcode));
Log('Start pypy 3');
Exec('cmd.exe', ExpandConstant('/c' +GetPythonPath('')+ '\python.exe {app}\test.py'),ExpandConstant('{app}'), SW_SHOW, ewWaitUntilTerminated, ResultCode);
Log(intToStr(Resultcode));