0
votes

I am trying to run a shell script from inno setup, but its failing. Here is my code:

procedure CurStepChanged(CurStep: TSetupStep);
var
  ErrorCode: Integer;
  cmdString: String;  
begin
if (CurStep=ssInstall)
then
   cmdString := 'net stop wuauserv'; 
   Exec(ExpandConstant('{cmd}'), '/C ' + cmdString, '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
if (CurStep=ssPostInstall)
then
cmdString := 'net start wuauserv'; 
Exec(ExpandConstant('{cmd}'), '/C ' + cmdString, '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
if Exec(ExpandConstant('{cmd}'), '/c {tmp}/wsus.bat', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
if (CurStep=ssDone)
then
cmdString := 'wuauclt /resetauthorization /detectnow & pause'; 
Exec(ExpandConstant('{cmd}'), '/C ' + cmdString, '', SW_SHOW, ewWaitUntilIdle, ErrorCode);
end;

The first 2 appear to run fine, the last command fails, with the error:

'wuauclt' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . .

Any suggestions? I believe its not setting the correct working directory, I've tried Exec(ExpandConstant('{win}'), Exec(ExpandConstant('{sys}') and Exec(ExpandConstant('{cmd}') to no avail.

1
If I were you, I would use Windows Update Agent API. - TLama
Thats a little too complex for what I am looking to achieve (or have the skill to do). The above command would be perfectly suitable for my goals without over complicating it.... if I could just figure out why it won't run correctly. As part of my install it copies a bat file to the app directory, if I run this outside the installer it works fine, but running it either via [RUN] or using the above statements it also fails. - copyandpaster
Trying again, the .bat file gets installed to the app directory and then is executed via inno setup file.. but still get the same error that wuauclt is not recognized, if I run the file directly from the app directory it works fine. - copyandpaster
The API I've suggested is really easy to use and much more reliable than the command line tools that you can't locate. Look at this example script which performs search for updates and returns available update count when the setup starts. It's based on this example. But I'm not here to convince you of this way :-) - TLama
This was also asked and answered on the Inno Setup news groups. - Deanna

1 Answers

1
votes

Using information you posted in the news groups, this was tracked down to a 32-bit vs 64-bit issue. 64-bit Windows machines do NOT have a wuauclt.exe in the 32-bit system folder.

Inno Setup is (by default) running in 32-bit mode so {cmd} (and {sys}) map to the 32-bit version which then access "C:\Windows\SysWoW64\".

To get around this, you should use two [Run] entries for "{sys}\wuauclt.exe", but one with the 64bit flag and an appropriate "IsWin64()" Check: parameter. the other should have an opposite "Not IsWin64()" check: parameter.

[Run]
Filename: "{sys}\wuauclt.exe"; Parameters: "/resetauthorization /detectnow"; Check: not IsWin64();
Filename: "{sys}\wuauclt.exe"; Parameters: "/resetauthorization /detectnow"; Flags: 64bit; Check: IsWin64();