【发布时间】:2020-08-13 11:17:52
【问题描述】:
我一直在尝试使用 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 的新手,谢谢大家! :)
【问题讨论】:
-
你用来为变量 $dst 编写 cmets 的那些是什么?您必须使用 # 在 Powershell 中编写 cmets。此外,Start-Process 不会那样工作,因为第一个参数需要 $dst,第二个参数需要 'FireFox-Installer.exe'。如果要加入路径,请使用 join-path
Start-Process (Join-Path $dst 'FireFox-Installer.exe') -
Opps,这不是我的代码的一部分,我只是写了这个,以便人们了解文件目标。谢谢你
-
不用担心。我编辑了我的第一条评论。尝试使用 join-path 创建一个正确的文件名,作为 Start-Process 的参数。
-
我现在使用此代码“Start-Process (Join-Path $dst 'FireFox-Installer.exe')”,但现在我得到一个不同的错误,即“Start-Process:此命令不能由于错误而被运行:系统找不到指定的文件。”
-
那么路径可能是错误的。将 Start-Process 行放在注释中并在其下方写入:
Write-Host (Join-Path $dst 'FireFox-Installer.exe')并检查路径是否正确。如果没有,你可能在 $dst 中构建路径时做错了
标签: powershell download execute