首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PowerShell StartProcess:无效的句柄

PowerShell StartProcess:无效的句柄
EN

Stack Overflow用户
提问于 2018-06-06 02:55:52
回答 2查看 1.3K关注 0票数 1

我正在尝试通过powershell在一台远程机器上安装google chrome。这就是我想要做的(我几乎是从不同网站上的一些其他帖子中拼凑而来的):

代码语言:javascript
复制
$Path = $env:TEMP; 

$Installer = "chrome_installer.exe";

(new-object System.Net.WebClient).DownloadFile('http://dl.google.com/chrome/install/375.126/chrome_installer.exe', "$Path\$Installer");

Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait;

Remove-Item $Path\$Installer 

在第四行失败了:Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait;

出现以下错误:

代码语言:javascript
复制
Start-Process : This command cannot be run due to the error: The handle is 
 invalid.
At line:1 char:2
+  Start-Process -FilePath $Path\$Installer -Args "/silent /install" -V ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOp 
   erationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C 
   ommands.StartProcessCommand

我对PowerShell非常缺乏经验,我很难弄清楚错误中的“句柄”是什么。如有任何帮助,我们将非常感谢:)

EDIT:在失败的命令周围加上一个try/catch { $_ | FL * -Force},它会给出以下输出:

代码语言:javascript
复制
PSMessageDetails      : 
Exception             : System.InvalidOperationException: This command cannot 
                        be run due to the error: The handle is invalid.
                           at System.Management.Automation.MshCommandRuntime.Th
                        rowTerminatingError(ErrorRecord errorRecord)
TargetObject          : 
CategoryInfo          : InvalidOperation: (:) [Start-Process], 
                        InvalidOperationException
FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands
                        .StartProcessCommand
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 4
PipelineIterationInfo : {}

相反,通过捕获$_.Exception,它提供了:

代码语言:javascript
复制
Message        : This command cannot be run due to the error: The handle is 
             invalid.
Data           : {}
InnerException : 
TargetSite     : Void ThrowTerminatingError(System.Management.Automation.ErrorR
                 ecord)
StackTrace     :    at System.Management.Automation.MshCommandRuntime.ThrowTerm
                 inatingError(ErrorRecord errorRecord)
HelpLink       : 
Source         : System.Management.Automation
HResult        : -2146233079
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-12 05:27:28

据我所知,这归结于这样一个事实:在Azure Web App环境中,您没有权限自由安装应用程序。

我猜环境的管理是受限制的,所以他们可以保证一定的服务水平。

你可以在这里了解更多:

https://docs.microsoft.com/en-us/azure/app-service/choose-web-site-cloud-service-vm

票数 0
EN

Stack Overflow用户

发布于 2018-06-06 04:04:20

尝试用双引号将提供给启动进程命令的进程引起来,或者使用$(Join-Path $Path $Installer)

现在,您正在为$Installer转义$,因此无法解析文件的路径。

代码语言:javascript
复制
Start-Process -FilePath "$Path\$Installer" -Args "/silent /install" -Verb RunAs -Wait;

# OR (even better I think)

Start-Process -FilePath $(Join-Path $Path $Installer) -Args "/silent /install" -Verb RunAs -Wait;
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50707140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档