AgentRev / WindowsAppsUnfukker

PowerShell script to fix WindowsApps-related permission errors and crashes.
The Unlicense
386 stars 23 forks source link

PsExec could not start powershell #13

Open manav0619 opened 1 year ago

manav0619 commented 1 year ago

Hello, I am running W11 22H2. I have been trying to fix my WindowsApps folder that I messed up permissions for and came across your script. However, it's not working for some reason on my PC. I keep getting the "PsExec could not start powershell…" error. I was wondering if you could assist me a bit. Any help will be truly appreciated.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\manav> cd J:\Users\manav\Downloads\PSTools
PS J:\Users\manav\Downloads\PSTools> .\psexec.exe -s -i powershell -ExecutionPolicy Bypass -File "J:\Users\manav\Downloads\WindowsAppsUnfukker-main\WindowsAppsUnfukker.ps1"

PsExec v2.4 - Execute processes remotely
Copyright (C) 2001-2022 Mark Russinovich
Sysinternals - www.sysinternals.com

PsExec could not start powershell on DESKTOP-99N6EMR:
The system cannot find the file specified.
AgentRev commented 1 year ago

It means Powershell cannot access the path to the script. In my experience, the usual culprit is network drives. I would say, try to move the script to a different drive.

manav0619 commented 1 year ago

@AgentRev Hey, thanks for responding. I don't actually have any network drives. Just two SSDs and two HDDs, all local. I have tried moving the script to different locations on every drive, but it's the exact same error every time. If you'd like to see any log file or system information that might help you identify the issue, I'd be happy to provide it. I really have no idea what's going wrong.

AgentRev commented 1 year ago

At that point, it's beyond my reach. You could use Process Monitor to investigate where is PsExec trying to look and why it's not resolving it. Other people have also recommended PAExec instead, maybe give that a try.

manav0619 commented 1 year ago

It wasn't PowerShell being unable to access the path to the script; it was rather PsExec being unable to access PowerShell.

I just added the full path to powershell.exe in the command, and it ended up working.

So, instead of

.\psexec.exe -s -i powershell -ExecutionPolicy Bypass -File "C:\WindowsAppsUnfukker-main\WindowsAppsUnfukker.ps1

I used

.\psexec.exe -s -i "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -File "C:\WindowsAppsUnfukker-main\WindowsAppsUnfukker.ps1

(I guess my environment variables are messed up as well? Because I had to add the System32 folder to "Path" under User Variables for takeown command to work when I was manually trying to fix the permissions earlier.)