瀏覽代碼

Use CREATE_NO_WINDOW if logging is enabled in all 3 cases to hide console programs but not GUI programs. Because of this also don't force SW_HIDE in ISPP ExecAndGetFirstLine. SignTool commands already didn't do SW_HIDE.

SignToolRunMinimized is now no longer needed? It now only applies to GUI sign tools and why would you want to run those minimized?
Martijn Laan 1 年之前
父節點
當前提交
68e60ca0d2
共有 6 個文件被更改,包括 22 次插入9 次删除
  1. 1 1
      Examples/PowerShell.iss
  2. 2 1
      ISHelp/isxfunc.xml
  3. 7 3
      Projects/ISPP/IsppFuncs.pas
  4. 5 1
      Projects/Src/Compile.pas
  5. 6 2
      Projects/Src/InstFunc.pas
  6. 1 1
      whatsnew.htm

+ 1 - 1
Examples/PowerShell.iss

@@ -59,7 +59,7 @@ end;
 function ExecAndGetFirstLine(const Filename, Params, WorkingDir: String; var ResultCode: Integer): String;
 begin
   Line := '';
-  ExecAndLogOutput(Filename, Params, WorkingDir, SW_HIDE, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog);
+  ExecAndLogOutput(Filename, Params, WorkingDir, SW_SHOW, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog);
   Result := Line;
 end;
 

+ 2 - 1
ISHelp/isxfunc.xml

@@ -2856,6 +2856,7 @@ end;</pre></example>
         <name>ExecAndLogOutput</name>
         <prototype>function ExecAndLogOutput(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer; const OnLog: TOnLog): Boolean;</prototype>
         <description><p>Identical to <link topic="isxfunc_Exec">Exec</link> except:</p>
+<p>Console programs are always hidden and the ShowCmd parameter only affects GUI programs, so always using <tt>SW_SHOW</tt> instead of <tt>SW_HIDE<tt> is recommended.</p>
 <p>If OnLog is set to <tt>nil</tt> then the output of the executed executable or batch file is logged in Setup's or Uninstall's log file and/or in the Compiler IDE's "Debug Output" view.</p>
 <p>If OnLog is not set to <tt>nil</tt> then the output is sent to the specified function, line by line.</p></description>
         <remarks><p>Parameter <tt>Wait</tt> must always be set to <tt>ewWaitUntilTerminated</tt> when calling this function.</p>
@@ -2876,7 +2877,7 @@ end;
 function ExecAndGetFirstLine(const Filename, Params, WorkingDir: String; var ResultCode: Integer): String;
 begin
   Line := '';
-  ExecAndLogOutput(Filename, Params, WorkingDir, SW_HIDE, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog);
+  ExecAndLogOutput(Filename, Params, WorkingDir, SW_SHOW, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog);
   Result := Line;
 end;</pre></example>
         <seealso><p><link topic="isxfunc_Exec">Exec</link></p></seealso>

+ 7 - 3
Projects/ISPP/IsppFuncs.pas

@@ -670,15 +670,19 @@ begin
     WorkingDirP := nil;
     
   var OutputReader: TCreateProcessOutputReader := nil;
-  var InheritHandles := False;
   try
+    var InheritHandles := False;
+    var dwCreationFlags: DWORD := CREATE_DEFAULT_ERROR_MODE;
+
     if Log and Assigned(LogProc) and WaitUntilTerminated then begin
       OutputReader := TCreateProcessOutputReader.Create(LogProc, LogProcData);
       OutputReader.UpdateStartupInfo(StartupInfo, InheritHandles);
+      if InheritHandles then
+        dwCreationFlags := dwCreationFlags or CREATE_NO_WINDOW;
     end;
 
     Result := CreateProcess(nil, PChar(CmdLine), nil, nil, InheritHandles,
-      CREATE_DEFAULT_ERROR_MODE, nil, WorkingDirP, StartupInfo, ProcessInfo);
+      dwCreationFlags, nil, WorkingDirP, StartupInfo, ProcessInfo);
     if not Result then begin
       ResultCode := GetLastError;
       Exit;
@@ -797,7 +801,7 @@ begin
       Data.Line := '';
       var ResultCode: Integer;
       var Success := Exec(Get(0).AsStr, ParamsS, WorkingDir, True,
-        SW_HIDE, Data.Preprocessor, True, ExecAndGetFirstLineLog, NativeInt(@Data), ResultCode);
+        SW_SHOW, Data.Preprocessor, True, ExecAndGetFirstLineLog, NativeInt(@Data), ResultCode);
       if Success then
         MakeStr(ResPtr^, Data.Line)
       else begin

+ 5 - 1
Projects/Src/Compile.pas

@@ -7383,10 +7383,14 @@ procedure TSetupCompiler.SignCommand(const AName, ACommand, AParams, AExeFilenam
     var OutputReader := TCreateProcessOutputReader.Create(SignCommandLog, NativeInt(Self));
     try
       var InheritHandles: Boolean;
+      var dwCreationFlags: DWORD := CREATE_DEFAULT_ERROR_MODE;
+
       OutputReader.UpdateStartupInfo(StartupInfo, InheritHandles);
+      if InheritHandles then
+        dwCreationFlags := dwCreationFlags or CREATE_NO_WINDOW;
 
       if not CreateProcess(nil, PChar(AFormattedCommand), nil, nil, InheritHandles,
-         CREATE_DEFAULT_ERROR_MODE, nil, PChar(CompilerDir), StartupInfo, ProcessInfo) then begin
+         dwCreationFlags, nil, PChar(CompilerDir), StartupInfo, ProcessInfo) then begin
         LastError := GetLastError;
         AbortCompileFmt(SCompilerSignToolCreateProcessFailed, [LastError,
           Win32ErrorString(LastError)]);

+ 6 - 2
Projects/Src/InstFunc.pas

@@ -899,15 +899,19 @@ begin
     WorkingDir := GetSystemDir;
 
   var OutputReader: TCreateProcessOutputReader := nil;
-  var InheritHandles := False;
   try
+    var InheritHandles := False;
+    var dwCreationFlags: DWORD := CREATE_DEFAULT_ERROR_MODE;
+
     if Log and Assigned(LogProc) and (Wait = ewWaitUntilTerminated) then begin
       OutputReader := TCreateProcessOutputReader.Create(LogProc, LogProcData);
       OutputReader.UpdateStartupInfo(StartupInfo, InheritHandles);
+      if InheritHandles then
+        dwCreationFlags := dwCreationFlags or CREATE_NO_WINDOW;
     end;
 
     Result := CreateProcessRedir(DisableFsRedir, nil, PChar(CmdLine), nil, nil,
-      InheritHandles, CREATE_DEFAULT_ERROR_MODE, nil, PChar(WorkingDir),
+      InheritHandles, dwCreationFlags, nil, PChar(WorkingDir),
       StartupInfo, ProcessInfo);
     if not Result then begin
       ResultCode := GetLastError;

+ 1 - 1
whatsnew.htm

@@ -140,7 +140,7 @@ end;</pre>
 <ul>
   <li>Added new <tt>[Run]</tt> and <tt>[UninstallRun]</tt> section flag <tt>logoutput</tt>. Instructs Setup and Uninstall to log the output of the executed program or batch file. Cannot be combined with the <tt>nowait</tt>, <tt>runasoriginaluser</tt>, <tt>shellexec</tt>, and <tt>waituntilidle</tt> flags. Has no effect if logging is not enabled.</li>
   <li>Added new <tt>[Setup]</tt> section directive <tt>UninstallLogging</tt>, which defaults to <tt>no</tt>. If set to <tt>yes</tt>, the uninstaller will always create a log file if it is launched from the <i>Add/Remove Programs</i> Control Panel applet. Equivalent to passing /LOG on the command line.</li>
-  <li>Digital signing change: Sign Tool output is now always logged in the Compiler IDE's "Compiler Output" view, making it easier to debug issues.</li>
+  <li>Digital signing change: Sign Tool output is now always logged in the Compiler IDE's "Compiler Output" view, making it easier to debug issues. Because of this, sign tools that are console programs will now always run hidden, as their output is being captured and they would display nothing in their window.</li>
   <li>Pascal Scripting change: Added new <tt>ExecAndLogOutput</tt> support function. Can be used to log the output of the executed program or batch file to Setup and Uninstall's log, or to receive the output line by line in your own <tt>[Code]</tt> function, for example to read the first non-empty line from the output as shown in the help file and the new <i>PowerShell.iss</i> example script.</li>
   <li>ISPP changes:
     <ul>