首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell下载和执行文件(文件或目录已损坏且不可读)

Powershell下载和执行文件(文件或目录已损坏且不可读)
EN

Stack Overflow用户
提问于 2020-08-13 19:17:52
回答 2查看 435关注 0票数 0

我一直在尝试用powershell下载和执行文件。一切正常,Powershell从"Workupload.com“下载文件并将其放入我的/user文件夹中。这对图片非常有效,下载后我也可以打开它们。

但是,当我在.exe或.txt文件中尝试它时,它不起作用。以下是我的代码:

代码语言:javascript
复制
$WebClient = New-Object System.Net.WebClient
$url = 'link to my .exe on workupload'
$dst = 'FireFox-Installer.exe' #Not adding a Path just puts the File in the User Folder
$WebClient.DownloadFile($url, $dst)
Start-Process $dst 'FireFox-Installer.exe'

现在,当我尝试打开该文件时,我得到一个错误,即文件已损坏且不可读。我想知道我该怎么解决这个问题..是Windows-Defender阻止了它吗?我的代码是错误的吗?或者是文件托管器导致了错误?

以下是我的错误代码:

代码语言:javascript
复制
Start-Process : This command cannot be run due to the error: The file or directory is corrupted and unreadable.
At line:1 char:1
+ Start-Process $dst 'FireFox-Installer.exe'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

非常感谢大家的帮助,因为我是Powershell的新手,谢谢大家!:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-13 22:48:28

好的,我试了一下,结果和预期的一样:

代码语言:javascript
复制
$WebClient = New-Object System.Net.WebClient
$url = 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/79.0/win32/en-US/Firefox%20Installer.exe'
$dst = 'C:\Temp'
$WebClient.DownloadFile($url, (Join-Path $dst 'FireFox-Installer.exe'))
Start-Process (Join-Path $dst 'FireFox-Installer.exe')

我刚刚为DownloadFile的destination参数添加了另一个Join-Path,如果它仍然不起作用,我建议您检查您的链接并测试您的Firefox-Installer.exe文件。

票数 0
EN

Stack Overflow用户

发布于 2020-10-20 02:49:53

如果您将目标根文件夹(例如\myserver\myshare)添加到IE中的受信任站点,然后关闭并重新启动PS会话,原始$dst是否可以工作?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63394008

复制
相关文章

相似问题

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