title: Why Delphi App can't run a *.bat file and make it work?
body: <p>The contents for the *.bat file:</p>
  
  <pre><code>cd "C:\Program Files\WinRAR"
  WinRAR a -r -ep1 "D:\Temp\250815\GiftCard-250815-1to10.zip" "D:\Temp\250815\word"
  </code></pre>
  
  <p>Basically, this file is telling WinRAR to compress the folder "word" into "GiftCard-250815-1to10.zip".</p>
  
  <p>The delphi line of code:</p>
  
  <pre><code>StartProcess('cmd.exe', '/C ' + 'D:\Temp\GenCards.bat', true, true);
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>ShellExecute(Handle, 'runas', PChar('C:\Program Files\WinRAR.exe a -r -ep1 "D:\Temp\250815\GiftCard-250815-1to10.zip" "D:\Temp\250815\word"'), nil, nil, SW_SHOWNORMAL);
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>ShellExecute(Handle, 'runas', 'cmd.exe', PChar('C:\Program Files\WinRAR.exe a -r -ep1 "D:\Temp\250815\GiftCard-250815-1to10.zip" "D:\Temp\250815\word"', nil, SW_SHOWNORMAL);
  </code></pre>
  
  <p>The fact is, I'm really lost here since, if I go to the folder and double click the *.bat file, it WORKS PERFECTLY!</p>
  
  <p>But, if I execute the bat from my code, it won't work.</p>
  
  <p><strong>* EDIT *</strong></p>
  
  <p>This is StartProcess function:</p>
  
  <pre><code>function TgenerateForm.StartProcess(ExeName: string; CmdLineArgs: string = ''; ShowWindow: boolean = True; WaitForFinish: boolean = False): integer;
  var
    StartInfo: TStartupInfo;
    ProcInfo: TProcessInformation;
  begin
    //Simple wrapper for the CreateProcess command
    //returns the process id of the started process.
    FillChar(StartInfo,SizeOf(TStartupInfo),#0);
    FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
    StartInfo.cb := SizeOf(TStartupInfo);
  
    if not(ShowWindow) then begin
      StartInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartInfo.wShowWindow := SW_HIDE;
    end;
  
    CreateProcess(nil,PChar(ExeName + ' ' + CmdLineArgs),nil,nil,False,
      CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS,nil,nil,StartInfo,
      ProcInfo);
  
    Result := ProcInfo.dwProcessId;
  
    if WaitForFinish then begin
      WaitForSingleObject(ProcInfo.hProcess,Infinite);
    end;
  
    //close process &amp; thread handles
    CloseHandle(ProcInfo.hProcess);
    CloseHandle(ProcInfo.hThread);
  end;
  </code></pre>
  
  <p>Please, do not be unpolite and copy &amp; paste a url. I searched all the stackoverflow and tried all "how-tos ... bat files".</p>