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是否有效?

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...