Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ColbyDash opened this issue Mar 26, 2022 · 24 comments

Comments

@ColbyDash
Copy link

ColbyDash commented Mar 26, 2022

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

@anthonycastaneda
Copy link

Are you running the script with PSexec or PAexec?

@adhdandy
Copy link

Same issue, no clue how to solve it.

@AgentRev
Copy link
Owner

AgentRev commented Feb 18, 2024

-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.

@adhdandy
Copy link

-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.

@AgentRev
Copy link
Owner

AgentRev commented Feb 19, 2024

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

@BakedCrossiant
Copy link

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

@AgentRev
Copy link
Owner

AgentRev commented Mar 9, 2024

What is the exact command line that you initially wrote?

@BakedCrossiant
Copy link

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.

@AgentRev
Copy link
Owner

AgentRev commented Mar 10, 2024

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

@BakedCrossiant
Copy link

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

@BCITMike
Copy link

BCITMike commented Mar 26, 2024

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

.
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!

@AgentRev
Copy link
Owner

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

@BCITMike
Copy link

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

@AgentRev
Copy link
Owner

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

@BCITMike
Copy link

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...:

@AgentRev
Copy link
Owner

Looks good, did it fix your original problem?

@BCITMike
Copy link

Looks good, did it fix your original problem?

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

@AgentRev
Copy link
Owner

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.

@BCITMike
Copy link

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.

@grayminds
Copy link

grayminds commented Mar 28, 2024

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.

@KIFIDOR
Copy link

KIFIDOR commented May 1, 2024

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!

@imprtns
Copy link

imprtns commented May 12, 2024

Hello @AgentRev, please help.

I have a very similar error and I really need help to unfukk this windows.
Thanks beforehand!

PAEXEC:

paexec -s -i cmd /C powershell -ExecutionPolicy Bypass -File "C:\Users\Username\Documents\Herramientas\WindowsAppsUnfukker-main\WindowsAppsUnfukker.ps1" "%LocalAppData%" ^|^| pause

Powershell:

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_20240512_024912.txt

Fixing WindowsApps subfolders inheritance...
Successfully processed 88 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\Username\AppData\Local\Packages_20240512_024914.txt
Successfully processed 1209 files; Failed processing 0 files
processed file: C:\Users\Username\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_20240512_024915.txt
Successfully processed 1 files; Failed processing 0 files
Successfully processed 13 files; Failed processing 0 files
Successfully processed 13 files; Failed processing 0 files
Successfully processed 13 files; Failed processing 0 files

Unfukking finished!! (hopefully)

CMD:

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}...

cmd returned -0

PAExec returning exit code -0

PSEXEC:

psexec -s -i cmd /C powershell -ExecutionPolicy Bypass -File "C:\Users\Username\Documents\Herramientas\WindowsAppsUnfukker-main\WindowsAppsUnfukker.ps1" "%LocalAppData%" ^|^| pause

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

Error creating key file on IMPRTNS:
The network path was not found.

Please Help. After all that Windows Store is still not working and apps are still not opening.

@AgentRev
Copy link
Owner

@imprtns The PAExec run looks fine. "Failed to impersonate" shouldn't be a problem if the exit code is 0. However, it says nothing under "Fixing WindowsApps subfolders permissions..." which is strange. Do you have a screenshot of the app errors?

@Aberdyfi
Copy link

"Failed to impersonate" indeed does not seem to be a problem in and of itself. I did get that message but it is very clear that WindowsAppsUnfukker ran successfully. (I can now launch apps, install apps, etc. Wow! Thanks for a fantastic script!) Here is the output from the cmd.exe window:

C:\Installation\Utilities>paexec -s -i cmd /C powershell -ExecutionPolicy Bypass -File "C:\Installation\Scripts\WindowsAppsUnfukker.ps1" "%LocalAppData%" ^|^| pause

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}...

cmd returned 0

PAExec returning exit code 0

Maybe there is something in my choice of folders for paexec or WindowsAppsUnfukker that paexec does not like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants