Reputation: 1047
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.
Upvotes: 4
Views: 6812
Reputation: 439607
@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
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.
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.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:
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
Upvotes: 5
Reputation: 21
Delete the powershell.exe (with 0KB) from location C:\Windows\System32 In my case Powershell working fine after deleting the powershell.exe (with 0KB) from system 32
Upvotes: 2