问题描述
我一直在尝试使用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是否有效?