The contents for the *.bat file:
cd "C:\Program Files\WinRAR"
WinRAR a -r -ep1 "D:\Temp\250815\GiftCard-250815-1to10.zip" "D:\Temp\250815\word"
Basically, this file is telling WinRAR to compress the folder "word" into "GiftCard-250815-1to10.zip".
The delphi line of code:
StartProcess('cmd.exe', '/C ' + 'D:\Temp\GenCards.bat', true, true);
I also tried:
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);
I also tried:
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);
The fact is, I'm really lost here since, if I go to the folder and double click the *.bat file, it WORKS PERFECTLY!
But, if I execute the bat from my code, it won't work.
* EDIT *
This is StartProcess function:
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 & thread handles
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;
Please, do not be unpolite and copy & paste a url. I searched all the stackoverflow and tried all "how-tos ... bat files".