2014-02-11 41 views
0

我想从inno安装程序运行一个shell脚本,但其失败。这里是我的代码:InnoSetup - 不识别shell脚本

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; 

第2显示一切正常,最后的命令失败,出现错误:

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

有什么建议?我相信它没有设置正确的工作目录,我试过Exec(ExpandConstant('{win}'),Exec(ExpandConstant('{sys}')和Exec(ExpandConstant('{cmd}')无济于事。

+0

如果我是你,我会使用Windows Update Agent API。 – TLama

+0

这对于我期望实现的(或者有技能的)来说有点太复杂。上述命令将完全适合我的目标,而不会使其复杂化......如果我能弄清楚为什么它不能正确运行。作为我安装的一部分,它将bat文件复制到应用程序目录,如果我在安装程序外部运行它可以正常工作,但是通过[RUN]或使用上述语句运行它也会失败。 – copyandpaster

+0

再试一次,.bat文件被安装到应用程序目录,然后通过inno安装文件执行..但仍然得到相同的错误,wuauclt无法识别,如果我直接从应用程序目录运行文件,它工作正常。 – copyandpaster

回答

1

使用您在新闻组发布信息,这被追查到的32位和64位的问题。 64位的Windows机器没有wuauclt.exe在32位系统文件夹。

Inno Setup的是(默认)在32位模式下运行,所以{cmd}(和{sys})映射到32位版本,然后访问。“C:\ WINDOWS \ SYSWOW64 \”

要解决这个问题,你应该使用两个[Run] en尝试使用“{sys} \ wuauclt.exe”,但使用64位标志和适当的“IsWin64()”Check:参数。另一个应该有一个相反的“Not IsWin64()”检查:参数。

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