簡體   English   中英

Windows 8.1無法從cmd或PowerShell提示符啟動Powershell - “此應用程序無法在您的PC上運行”

[英]Windows 8.1 can't start Powershell from a cmd or powershell prompt - “This app can't run on your PC”

Powershell突然從cmd和powershell提示中退出。 我沒有在它工作和退出工作之間安裝任何新東西。

當我嘗試使用以下命令從cmd窗口(提升和未提升)啟動powershell.exe時

C:\Users\myuser>powershell.exe

我從操作系統中得到一個彈出錯誤,說:

This app can't run on your PC

一旦我關閉了彈出窗口,我就打開了cmd提示符,然后打印出來:

Access is denied

到屏幕(是的,即使我在高架cmd提示符下執行此操作)

當我嘗試使用以下命令在powershell中執行此操作時:

PS C:\Users\myuser> powershell.exe

我明白了:

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

顯然,即使是powershell也不再喜歡PowerShell了。

我已經嘗試重新啟動計算機並且沒有解決它,但我完全陷入了下一步該做什么的困境。

@ 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環境變量中列出的目錄中存在的所有可執行文件。
    請注意,與Get-Command不同, where.exe也會在當前目錄中查找,並首先查看。
    因此,返回的第一個路徑是僅在指定可執行文件時實際執行的可執行文件。

    • 請注意, 當前目錄中的匹配項(如果找到where.exe )僅在從cmd.exe (從命令提示符或批處理文件)調用可執行文件時才會where.exe ,因為PowerShell的設計不允許從中調用可執行文件當前目錄僅僅是名字。
    • 如果你想運行where.exe從PowerShell中,擴展.exe是必需的,因為該命令名where通過本身內置的別名Where-Object cmdlet的。
  • where.exe / Get-Command的輸出中,檢查:

    • 如果首先列出您期望的可執行文件。
    • 如果它的大小不為零。
  • 刪除意外(零字節)可執行文件,或者,如果您希望它們作為正常運行的可執行文件存在,請重新安裝它們。


例:

在當前目錄和$env:PATH列出的目錄中查找名為powershell.exe所有可執行文件。

請注意, powershell.exe的正確主目錄是C:\\Windows\\System32\\WindowsPowerShell\\v1.0 ,如$PSHOME

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

where powershell.exe 

示例輸出:

C:\Windows\System32\powershell.exe
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

來自PowerShell:

Get-Command -All powershell.exe

如果您還想查看當前目錄,請使用
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

如果要在輸出中包含文件大小:

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

刪除從位置C中的powershell.exe(與0KB):\\ Windows \\ System32下我的情況PowerShell的工作的罰款從系統32刪除powershell.exe(與0KB)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM