简体   繁体   中英

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

Powershell suddenly quit opening from both cmd and powershell prompts. I haven't installed anything new between when it did work and when it quit working.

When I try to start powershell.exe from a cmd window (both elevated and not elevated) with the following command

C:\Users\myuser>powershell.exe

I get a popup error from the OS that says:

This app can't run on your PC

Once I close that popup the cmd prompt I made the call from then prints:

Access is denied

To the screen (yes even when I do this in an elevated cmd prompt)

When I try to do it in powershell with the following command:

PS C:\Users\myuser> powershell.exe

I get:

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

Apparently even powershell doesn't like powershell anymore.

I've tried restarting the computer and that didn't fix it, but I'm totally stymied as to what to do next.

@ PetSerAl gave the crucial pointer in comments on the question.

The "This app can't run on your PC" pop-up error message on Windows 8 or above Windows 8+上的“此应用程序无法在您的PC上运行”弹出错误消息 indicates:

  • a corrupted file, such as a 0-byte *.exe file , esp. when followed by an "Access denied" error in the console.

  • or, increasingly less commonly, an attempt to run a 64-bit executable on a 32-bit edition of Windows.

Troubleshooting steps:

  • From a Command Prompt ( cmd.exe console), run where.exe <executable-name> ;
    from PowerShell, run Get-Command -All <executable-name> , which shows you all executables by that name present in the directories listed in the $env:PATH environment variable in that order, by their full paths.
    Note that where.exe , unlike Get-Command , also looks in the current directory, and looks there first .
    Thus, the first path returned is the executable that is actually executed when only the executable name is specified.

    • Note that a match in the current directory, if found by where.exe , only matters when calling the executable from cmd.exe (from the Command Prompt or a batch file), because PowerShell by design doesn't allow invocation of executables from the current directory by mere name.
    • If you want to run where.exe from PowerShell, extension .exe is required, because the command name where by itself is a built-in alias for the Where-Object cmdlet.
  • In the output from where.exe / Get-Command , check:

    • if the executable you expect is listed first.
    • if its size is non-zero.
  • Remove unexpected (zero-byte) executables, or, if you expect them to be there as functioning executables, reinstall them.


Example:

Look for all all executables named powershell.exe in the current directory and in the directories listed in $env:PATH .

Note that the proper home of powershell.exe is C:\\Windows\\System32\\WindowsPowerShell\\v1.0 , as reflected in $PSHOME .

From cmd.exe (regular Command Prompt):

where powershell.exe 

Example output:

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

From PowerShell:

Get-Command -All powershell.exe

If you also want to look in the current directory, use
Get-Command -All .\\powershell.exe, powershell.exe

Example output:

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

If you want to include the file size in the output:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM