Windows 8.1无法从cmd或Powershell提示符启动Powershell-“此应用程序无法在您的PC上运行”

Tuf*_*wer 4 windows powershell

Powershell突然从cmd和powershell提示中退出打开。在它工作时和退出工作之间,我尚未安装任何新产品。

当我尝试使用以下命令从cmd窗口(提升和不提升)启动powershell.exe时

C:\Users\myuser>powershell.exe
Run Code Online (Sandbox Code Playgroud)

我从操作系统中收到一个弹出错误,提示:

This app can't run on your PC
Run Code Online (Sandbox Code Playgroud)

关闭该弹出窗口后,我会从cmd提示进行呼叫,然后打印:

Access is denied
Run Code Online (Sandbox Code Playgroud)

到屏幕上(是的,即使我在提升的cmd提示符下执行此操作)

当我尝试使用以下命令在powershell中执行此操作时:

PS C:\Users\myuser> powershell.exe
Run Code Online (Sandbox Code Playgroud)

我得到:

Program 'powershell.exe' failed to run: The specified executable is not a valid application for this OS platform.
At line:1 char:1
+ powershell.exe
+ ~~~~~~~~~~~~~~.
At line:1 char:1
+ powershell.exe
+ ~~~~~~~~~~~~~~.
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorID : NativeCommandFailed
Run Code Online (Sandbox Code Playgroud)

显然,甚至powershell不再喜欢powershell。

我曾尝试重新启动计算机,但仍无法解决问题,但我完全受其下一步的困扰。

mkl*_*nt0 5

@ PetSerAl在对该问题的评论中给出了关键指针。

Windows 8或更高版本上显示“此应用程序无法在您的PC上运行”弹出错误消息 Windows 8+上的“此应用程序无法在您的PC上运行”弹出错误消息 表示:

  • 一个损坏的文件,例如一个0字节*.exe文件,电除尘器。当控制台中出现“访问被拒绝”错误时。

  • 或者越来越不常见的尝试是在32位版本的Windows上运行64位可执行文件。

故障排除步骤:

  • 从命令提示符(cmd.exe控制台),运行where.exe <executable-name>
    在PowerShell中运行Get-Command -All <executable-name>,它会$env:PATH以其完整路径显示所有可执行文件,其名称按该变量存在于环境变量列出的目录中的顺序显示。
    请注意where.exe,与有所不同Get-Command,它还会在当前目录中查找,并首先在该目录中查找。
    因此,返回的第一个路径是当仅指定可执行文件名称时实际执行的可执行文件。

    • 请注意,当前目录中的匹配项(如果由找到where.exe)仅在从cmd.exe(从命令提示符或批处理文件)中调用可执行文件时才有意义,因为PowerShell故意设计为不允许从名称中调用当前目录中的可执行文件。
    • 如果where.exe要从PowerShell 运行,.exe则需要扩展名,因为命令名称where本身是Where-Objectcmdlet 的内置别名。
  • where.exe/ 的输出中Get-Command,检查:

    • 如果您期望的可执行文件位于第一位。
    • 如果其大小不为零。
  • 删除意外的(零字节)可执行文件,或者,如果您希望它们作为可运行的可执行文件存在,请重新安装它们。


例:

powershell.exe在当前目录和中列出的目录中查找所有命名的可执行文件$env:PATH

注意的适当的家庭powershell.exe就是C:\Windows\System32\WindowsPowerShell\v1.0,所反映的$PSHOME

cmd.exe(常规命令提示符):

where powershell.exe 
Run Code Online (Sandbox Code Playgroud)

输出示例:

C:\Windows\System32\powershell.exe
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Run Code Online (Sandbox Code Playgroud)

从PowerShell:

Get-Command -All powershell.exe
Run Code Online (Sandbox Code Playgroud)

如果您还想查看当前目录,请使用
Get-Command -All .\powershell.exe, powershell.exe

输出示例:

CommandType     Name            Version    Source
-----------     ----            -------    ------
Application     powershell.exe  0.0.0.0    C:\WINDOWS\system32\powershell.exe
Application     powershell.exe  10.0.14... C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Run Code Online (Sandbox Code Playgroud)

如果要在输出中包括文件大小:

PS> where.exe powershell.exe | % { [system.io.fileinfo] $_ |
  select fullname, length, @{ n = 'Version'; e = { $_.versioninfo.FileversionRaw } } }

FullName                                                  Length Version
--------                                                  ------ -------
C:\Windows\System32\powershell.exe                             0
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 446976 10.0.14393.206
Run Code Online (Sandbox Code Playgroud)