如何解决Powershell下载和执行文件文件或目录已损坏且无法读取
我一直在尝试使用powershell下载和执行文件。一切正常,Powershell从“ Workupload.com”下载文件,并将其放在我的/ user文件夹中。 这与图片完美搭配,下载后我也可以打开它们。
但是,当我使用.exe或.txt文件尝试操作时,它不起作用。 这是我的代码:
$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是否阻止了它?我的代码有误吗?还是导致错误的File-Hoster?
这是我的错误代码:
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的新手,我们将非常感谢他们的帮助,谢谢大家! :)
解决方法
好吧,所以我尝试了一下,它按预期工作了:
child:
// Text(
// "Hello Programmer",// style: TextStyle(fontSize: 18),// ),Html(data:"<p>Hello <b>Flutter</b><p>"),
我刚刚为目标$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')
添加了另一个Join-Path
如果仍然无法正常工作,建议您检查链接并测试Firefox-Installer.exe文件。
如果将目标根文件夹(例如\\ myserver \ myshare)添加到IE中的“受信任的站点”,然后关闭并重新启动PS会话,原来的$ dst是否有效?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。