我正在编写一个功能,该功能将为我的设备安装必需的组件,该组件基于PowerShell。如果找不到特定版本的PowerShell,我希望安装程序帮助用户安装它。我遇到的问题是如何正确调用脱机安装程序进行安装。这是我拥有的代码,它是一个通用函数(我正在使用InnoSetup Dependency Installer):
function SmartExec(product : TProduct; var resultcode : Integer): boolean;
begin
if (LowerCase(Copy(product.File, Length(product.File) - 2, 3)) = 'exe') then begin
Result := Exec(product.File, product.Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, resultcode);
end else begin
Result := ShellExec('', product.File, product.Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, resultcode);
end;
end;
我尝试使用以下方法:
function SmartExec(product : TProduct; var resultcode : Integer): boolean;
begin
if (LowerCase(Copy(product.File, Length(product.File) - 2, 3)) = 'exe') then begin
Result := Exec(product.File, product.Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, resultcode);
end else if (LowerCase(Copy(product.File, Length(product.File) - 2, 3)) = 'msu') then begin
Result := ShellExec('', 'wusa.exe ' + product.File, product.Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, resultcode);
end else begin
Result := ShellExec('', product.File, product.Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, resultcode);
end;
end;
当我编译并测试安装程序时,会遇到以下问题:
我将/quiet /norestart
参数作为参数传递给MSU文件,该文件可以在命令提示符下完美执行。
安装文件已下载到%tmp%
当前用户,我可以看到该文件。
有任何帮助或意见吗?
该.msu
扩展名与关联wusa.exe
,因此现有分支ShellExec('', product.File, ...)
应完成此工作。您不需要添加特定的msu
分支。
无论如何,特定的分支可以帮助调试,因此值得尝试。
ShellExec
函数的第二个参数是FileName
,当您传入时wusa.exe xxx.msu
,它不是有效的文件名。
这应该工作:
Result := ShellExec('', 'wusa.exe', product.File + ' ' + product.Parameters, ...);
尽管使用ShellExec
来运行可执行文件是一个过大的选择,但应使用普通Exec
函数:
Result := Exec('wusa.exe', product.File + ' ' + product.Parameters, ...);
当Exec
返回False
时,ResultCode
是Windows错误代码解释为什么执行失败。您将得到代码3,这是什么ERROR_PATH_NOT_FOUND
(系统找不到指定的路径。)。
因此,看来您使用的路径(product.File
)无效。
确保将完整路径传递给.msu
,而不仅仅是文件名。
在调用之前尝试记录路径,Exec
并检查文件是否存在。您可以使用:
Log(Format('Path is [%s], Exists = %d', [product.File, Integer(FileExists(product.File))]));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句