WindowsAppsUnfukker icon indicating copy to clipboard operation
WindowsAppsUnfukker copied to clipboard

"Failed to impersonate [] - continuing anyway. The handle is invalid. [Err=0x6, 6]"

Open ColbyDash opened this issue 2 years ago • 24 comments

Wish I could use this script to unfuck my royally fucked pc but I keep running into this error:

Failed to impersonate [] - continuing anyway. The handle is invalid. [Err=0x6, 6] Starting PAExec service on {local server}...

powershell returned -196608

PAExec returning exit code -196608

EDIT: Tried running with my firewall disabled as #5 said to do but it didn't work :p

ColbyDash avatar Mar 26 '22 20:03 ColbyDash

Are you running the script with PSexec or PAexec?

anthonycastaneda avatar Mar 27 '22 10:03 anthonycastaneda

Same issue, no clue how to solve it.

adhdandy avatar Feb 18 '24 15:02 adhdandy

-196608 is the error code usually returned by PowerShell when it cannot resolve the path from the -File parameter. If you copy-pasted the command line as-is from my readme, it will produce that error code, since you need to change FULL_PATH_HERE first. If you did change it, double-check the path you entered. If the path is fine but you still get that code, try running the PowerShell command without the paexec.exe -s -i to see if it gives a more specific error message.

AgentRev avatar Feb 18 '24 17:02 AgentRev

-196608 is the error code usually returned by PowerShell when it cannot resolve the path from the -File parameter. If you copy-pasted the command line as-is from my readme, it will produce that error code, since you need to change FULL_PATH_HERE first. If you did change it, double-check the path you entered. If the path is fine but you still get that code, try running the PowerShell command without the paexec.exe -s -i to see if it gives a more specific error message.

I thought using a relative path when starting the script from the same directory WindowsAppsUnfukker.ps1 is in would work, but apparently I was wrong. Using the absolute path to the file instead worked, unfortunately the script didn't fix my error, oh well.

adhdandy avatar Feb 19 '24 11:02 adhdandy

What is the error you're getting? I'm planning to release an update this week to cover another type of error somebody else found, maybe it will solve it

AgentRev avatar Feb 19 '24 13:02 AgentRev

I got this error when using powershell, threw up the same unable to impersonate error.

At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:11 {"payload":{"allShortcutsEnabled":true,"fileTree":{"":{"items":[{"nam ...

Unexpected token ':' in expression or statement. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:34 {"payload":{"allShortcutsEnabled":true,"fileTree":{"":{"items":[{"nam ...

Unexpected token ':true' in expression or statement. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:39 {"payload":{"allShortcutsEnabled":true,"fileTree":{"":{"items":[{"nam ...

Missing argument in parameter list. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:54 {"payload":{"allShortcutsEnabled":true,"fileTree":{"":{"items":[{"nam ...

Unexpected token ':' in expression or statement. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:63 ... ayload":{"allShortcutsEnabled":true,"fileTree":{"":{"items":[{"name": ...

Unexpected token ':[' in expression or statement. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:72 ... sEnabled":true,"fileTree":{"":{"items":[{"name":"LICENSE.txt","path": ...

Unexpected token ':"LICENSE.txt"' in expression or statement. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:86 ... Enabled":true,"fileTree":{"":{"items":[{"name":"LICENSE.txt","path":" ...

Missing argument in parameter list. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:137 ... path":"LICENSE.txt","contentType":"file"},{"name":"README.md","path": ...

Unexpected token ':"README.md"' in expression or statement. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:149 ... ath":"LICENSE.txt","contentType":"file"},{"name":"README.md","path":" ...

Missing argument in parameter list. At C:\Users...\Downloads\WindowsAppsUnfukker.ps1:1 char:198 ... E.md","contentType":"file"},{"name":"WindowsAppsUnfukker.ps1","path": ... +
Unexpected token ':"WindowsAppsUnfukker.ps1"' in expression or statement. Not all parse errors were reported. Correct the reported errors and try again. CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException FullyQualifiedErrorId : UnexpectedToken

BakedCrossiant avatar Mar 06 '24 11:03 BakedCrossiant

What is the exact command line that you initially wrote?

AgentRev avatar Mar 09 '24 18:03 AgentRev

powershell -ExecutionPolicy Bypass -File "C:\Users...\Downloads\WindowsAppsUnfukker.ps1" "%LocalAppData%"

I removed the paexec.exe -s -i to get the full error message. I also cd' into the paexec directory beforehand.

BakedCrossiant avatar Mar 10 '24 09:03 BakedCrossiant

I think you downloaded the script incorrectly, the {"payload":{"allShortcutsEnabled":true,"fileTree":{"":{"items":[{"nam ... stuff comes from GitHub HTML code and should not be part of the file. Try obtaining it using this link: https://github.com/AgentRev/WindowsAppsUnfukker/archive/refs/heads/main.zip

AgentRev avatar Mar 10 '24 16:03 AgentRev

That worked, but I'm still having problems with Windows Apps. Thanks anyway!

BakedCrossiant avatar Mar 14 '24 08:03 BakedCrossiant

I'm having this problem on a windows 11 PC. When I try to view properties of "C:\Program Files\WindowsApps", I get a warning that I can't read the permissions (edit: I think this is just the difference between another PC with UAC disabled vs this PC that prompts for UAC).

I have paexec and this script in c:\mike and get:

c:\mike>powershell -ExecutionPolicy Bypass -File "c:\mike\WindowsAppsUnfukker.ps1" "%LocalAppData%"

Welcome to the amazing WindowsApps Unfukker! Please sit tight!!

Error: Not running as SYSTEM user!! Please start this script via PAExec.

Press Enter to continue...:

c:\mike>paexec -s -i powershell -ExecutionPolicy Bypass -File "C:\mike\WindowsAppsUnfukker.ps1" "%LocalAppData%"

PAExec v1.29 - Execute Programs Remotely Copyright (c) 2012-2021 Power Admin LLC www.poweradmin.com/PAExec

Connecting to {local server}... Failed to impersonate [] - continuing anyway. The handle is invalid. [Err=0x6, 6] Starting PAExec service on {local server}...

Welcome to the amazing WindowsApps Unfukker! Please sit tight!!

Fixing WindowsApps permissions... Backup of existing permissions... Successfully processed 0 files; Failed processing 0 files Saved to C:\Program Files\WindowsApps_20240325_224858.txt

Fixing WindowsApps subfolders inheritance... Successfully processed 309 files; Failed processing 0 files

Fixing WindowsApps subfolders permissions...

Fixing AppData Packages permissions, this could take a couple minutes... Backup of existing permissions... Successfully processed 0 files; Failed processing 0 files Saved to C:\Users\Computer003\AppData\Local\Packages_20240325_224939.txt Successfully processed 14838 files; Failed processing 0 files processed file: C:\Users\Computer003\AppData\Local\Packages Successfully processed 1 files; Failed processing 0 files

Fixing ProgramData Packages permissions... Backup of existing permissions... Successfully processed 0 files; Failed processing 0 files Saved to C:\ProgramData\Packages_20240325_224955.txt Successfully processed 1 files; Failed processing 0 files Successfully processed 245 files; Failed processing 0 files Successfully processed 245 files; Failed processing 0 files Successfully processed 245 files; Failed processing 0 files

Unfukking finished!! (hopefully)

Press Enter to continue...:

c:\mike>dir Volume in drive C has no label. Volume Serial Number is DA74-C959

Directory of c:\mike

03/25/2024 10:14 PM <DIR> . 03/25/2024 08:28 PM 224,560 paexec.exe 03/25/2024 10:14 PM 716,176 PsExec.exe 03/25/2024 08:29 PM 10,002 WindowsAppsUnfukker.ps1 3 File(s) 950,738 bytes 1 Dir(s) 383,267,962,880 bytes free

Any idea where to go from here?

Thanks in advance!

BCITMike avatar Mar 26 '24 05:03 BCITMike

If you enter echo %ERRORLEVEL% after the paexec, what number does it say?

AgentRev avatar Mar 26 '24 05:03 AgentRev

If you enter echo %ERRORLEVEL% after the paexec, what number does it say?

Sorry, I missed that.

PAExec v1.29 - Execute Programs Remotely Copyright (c) 2012-2021 Power Admin LLC www.poweradmin.com/PAExec

Connecting to {local server}... Failed to impersonate [] - continuing anyway. The handle is invalid. [Err=0x6, 6] Starting PAExec service on {local server}...

powershell returned 0

PAExec returning exit code 0

BCITMike avatar Mar 26 '24 05:03 BCITMike

Huh, weird. How about with PsExec? https://learn.microsoft.com/en-us/sysinternals/downloads/psexec

AgentRev avatar Mar 26 '24 06:03 AgentRev

Huh, weird. How about with PsExec? https://learn.microsoft.com/en-us/sysinternals/downloads/psexec

c:\mike>psexec -s -i powershell -ExecutionPolicy Bypass -File "C:\mike\WindowsAppsUnfukker.ps1" "%LocalAppData%"

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

powershell exited on DESKTOP-Q7L7CHT with error code 0.

c:\mike>echo %ERRORLEVEL% 0

Welcome to the amazing WindowsApps Unfukker! Please sit tight!!

Fixing WindowsApps permissions... Backup of existing permissions... Successfully processed 0 files; Failed processing 0 files Saved to C:\Program Files\WindowsApps_20240325_233256.txt

Fixing WindowsApps subfolders inheritance... Successfully processed 309 files; Failed processing 0 files

Fixing WindowsApps subfolders permissions... Fixing C:\Program Files\WindowsApps\Microsoft.VCLibs.140.00_14.0.33519.0_x86__8wekyb3d8bbwe-old

Fixing AppData Packages permissions, this could take a couple minutes... Backup of existing permissions... Successfully processed 0 files; Failed processing 0 files Saved to C:\Users\Computer003\AppData\Local\Packages_20240325_233337.txt Successfully processed 14941 files; Failed processing 0 files processed file: C:\Users\Computer003\AppData\Local\Packages Successfully processed 1 files; Failed processing 0 files

Fixing ProgramData Packages permissions... Backup of existing permissions... Successfully processed 0 files; Failed processing 0 files Saved to C:\ProgramData\Packages_20240325_233351.txt Successfully processed 1 files; Failed processing 0 files Successfully processed 251 files; Failed processing 0 files Successfully processed 251 files; Failed processing 0 files Successfully processed 251 files; Failed processing 0 files

Unfukking finished!! (hopefully)

Press Enter to continue...:

BCITMike avatar Mar 26 '24 06:03 BCITMike

Looks good, did it fix your original problem?

AgentRev avatar Mar 26 '24 06:03 AgentRev

Looks good, did it fix your original problem?

Unfortunately not, I still cannot open Windows Store or open any store apps like Photos.

BCITMike avatar Mar 26 '24 06:03 BCITMike

Hmm, maybe it's the AppRepository folder, which I haven't had the time to implement yet. It will definitely take an entire day to tear it apart and test the result, and I just don't have that kinda spare time at the very moment.

AgentRev avatar Mar 26 '24 07:03 AgentRev

Hmm, maybe it's the AppRepository folder, which I haven't had the time to implement yet. It will definitely take an entire day to tear it apart and test the result, and I just don't have that kinda spare time at the very moment.

Yeah, I think so. I tried mucking with it but still got access denied and made things worse. I tried doing an export/import of permissions using icacls but the import didn't get any matches and didn't do anything. Ended up doing a clean install and migrating using pcmover and luckily the store still worked.

Appreciate your help and your contribution to fixing this problem.

BCITMike avatar Mar 26 '24 11:03 BCITMike

POSTING MY MISTAKE WITH ANSWER BELOW Following... From Admin Cmd prompt:

`C:\Temp\WindowsAppsFix>paexec -s -i powershell -ExecutionPolicy Bypass -File "C:\Temp\WindowsAppsFix\WindowsAppsUnfukker.ps1" "%LocalAppData%"

PAExec v1.29 - Execute Programs Remotely Copyright (c) 2012-2021 Power Admin LLC www.poweradmin.com/PAExec

Connecting to {local server}... Failed to impersonate [] - continuing anyway. The handle is invalid. [Err=0x6, 6] Starting PAExec service on {local server}...

powershell returned 1

PAExec returning exit code 1

C:\Temp\WindowsAppsFix>`

CLARIFICATION FOR FUTURE READERS Do Not right click and download from Github file listing.... Click on the ps1 file then the Download icon on the right. If you check the file locally, it should be a powershell file, not with an HTML wrapper.

grayminds avatar Mar 28 '24 04:03 grayminds

Just wanted to comment it worked for me after trying different things. It can be kind of difficult for some if you are not too familiar with CMD or Shell, not even to mention PsExec or its variant.

  • After downloading the PAExec, make sure you place it on "C:\Windows\System32"
  • If after trying to run it on CMD it's still not working, try using Shell instead. If your issue persists on both, Shell and CMD, proceed with PsExec instead of PAExec (https://download.sysinternals.com/files/PSTools.zip). You just download it, un-zip it and then place the files (not the folder) on the same path as before - "C:\Windows\System32". Then proceed with the original tutorial, just replace the parts where PAExec is mentioned for PsExec

Have to say I've been trying to run the code for about 2 hours straight and I was about to give up, but then I tried using PsExec as some suggested and it did the trick. After the code runs successfully, I think it takes about 5 - 10 minutes to complete, but maybe it depends on your system. After the process completed, I was able to run my programs again as usual and I no longer have permission to open the "WindowsApps" folder

Now, I just want to say: Thank you!

KIFIDOR avatar May 01 '24 09:05 KIFIDOR