Using Powershell to delete REG key for all users

Page 1 of 2 12 LastLast

  1. Posts : 43
    Windows 10 Pro Insider
       #1

    Using Powershell to delete REG key for all users


    Hey all, not sure if this is the right place to ask, especially considering how pointed the question is.

    We're trying to do a thorough clean install of a software due to changing the version (specifically, we're moving from SolidWorks 2017 to 2020 SP04). However, the issue is that uninstalling everything just doesn't actually clean everything. There seems to always be something left, especially in the registry. And of course, part of the registry is exclusive to each user, meaning I just can't clean everything through the Admin account.

    So the question is this: Knowing that HKEY_USERS should contain all users that are on the computer, can I, through a Powershell script or something, delete the relevant registry keys for all users on the computer and how.

    I've managed to find a few snippets of Powershell code through Google but it's not always clear what it does or why, and most importantly what I need to adapt.

    So yeah, anyone got maybe some pointers?
      My Computers


  2. Posts : 43,029
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, quite agree many authors are not efficient in creating their uninstallers.

    Why not use tools meant for the job? Revo Uninstaller, Geek uninstaller, then there's Wise Uninstaller which included Forced Uninstall in the free version?

    I routinely use Geek Uninstaller (faster to launch than Revo).

    These launch the standard uninstallers, then perform a scan for leftovers. Forced Uninstall lets you browse to some part of the program and start an uninstall scan from that - e.g. when the installation is damaged.

    Pro versions include monitoring the installation and creating a log on which uninstalling can be based.

    I don't know of options for a per user uninstall, though.
      My Computers


  3. Posts : 14,026
    Win10 Pro and Home, Win11 Pro and Home, Win7, Linux Mint
       #3

    I agree, to fully clean the Registry for each user requires that user being logged as each user has their own version of the Registry in their Folder and others can't or shouldn't be able to access it. I haven't tried using the hidden/default Administrator account to access all the files for all users.
      My Computers


  4. Posts : 1,776
    Windows 10 Pro
       #4

    dalchina said:
    Hi, quite agree many authors are not efficient in creating their uninstallers.

    Why not use tools meant for the job? Revo Uninstaller, Geek uninstaller, then there's Wise Uninstaller which included Forced Uninstall in the free version?

    I routinely use Geek Uninstaller (faster to launch than Revo).

    These launch the standard uninstallers, then perform a scan for leftovers. Forced Uninstall lets you browse to some part of the program and start an uninstall scan from that - e.g. when the installation is damaged.

    Pro versions include monitoring the installation and creating a log on which uninstalling can be based.

    I don't know of options for a per user uninstall, though.
    +1 to the paid version of Revo.
      My Computers


  5. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #5

    Hello @fenrir0wulf,

    I usually find that Revo Uninstaller and Geek Uninstaller are more than qualified for this sort of task.

    I hope this helps!
      My Computer


  6. Posts : 1,777
    Windows 10 Pro (+ Windows 10 Home VMs for testing)
       #6

    You haven't mentioned what environment you're in so I'm going to assume Domain.

    To iterate through HKEY_USERS to do this for all users then you need all user profiles to be unloaded ('cos otherwise a logged-in user will have their NTUSER.DAT file locked for bulk editing).

    However, if all users are logged out then you'll need to log in remotely as admin... and seach/replacement of registry keys of remote users is slow - particularly with devices used by multiple users - and a pain to set up and test beforehand unless you have a test environment.

    I'm retired and no longer have an environment to test but, off the top of my head, you would be using:
    Code:
    $users = (Get-ChildItem -path c:\users).name
    foreach($user in $users)
     {
     reg load "hku\$user" "C:\Users\$user\NTUSER.DAT"
     # Do whatever you need with "hkey_users\$user" here which links to each users' HKU
     # Example: Delete the 'Connected PDF' key without asking for confirmation
     reg delete "hkey_users\$user\SOFTWARE\Foxit Software\Foxit Reader\ConnectedPDF" /f
     reg unload "hku\$user"
     }

    Alternatively, use Remove-Item -Path instead of reg delete.

    I suggest a login script that makes the changes for each individual user will be easier for you to test and implement, even without a seperate test environment.

    Hope this helps...
    Last edited by RickC; 18 Aug 2020 at 16:28.
      My Computer


  7. Posts : 43
    Windows 10 Pro Insider
    Thread Starter
       #7

    RickC said:
    Code:
    $users = (Get-ChildItem -path c:\users).name
    foreach($user in $users)
     {
     reg load "hku\$user" "C:\Users\$user\NTUSER.DAT"
     # Do whatever you need with "hkey_users\$user" here which links to each users' HKU
     # Example: Delete the 'Connected PDF' key without asking for confirmation
     reg delete "hkey_users\$user\SOFTWARE\Foxit Software\Foxit Reader\ConnectedPDF" /f
     reg unload "hku\$user"
     }
    Hah! That is literally the piece of code I found when googling. I guess this at least confirms that it works. Fortunately, I have a computer ready for testing. I'll try that and Revo.
      My Computers


  8. Posts : 43
    Windows 10 Pro Insider
    Thread Starter
       #8

    Hey, sorry for the delayed update, but my schedule changed drastically recently.

    So, first off, I tried Revo. It ended up being horrifically slow, and kept borking in the middle of the uninstall. So I dropped it.

    Then I tried Wise, both the uninstaller as well as the Reg cleaner. While it uninstalled fine, the Reg cleaner did not in fact manage to do what I was hoping for. Which is to say, to remove everything for every user on the computer.

    So now I've tried using the Powershell code. I've modified it for my needs but unfortunately there still seems to be an issue.
    Code:
    Erreur : Le processus ne peut pas accéder au fichier car ce fichier est utilisé par un autre processus.
    Remove-Item : Impossible de trouver le chemin d'accès «C:\Users\Administrateur\Desktop\hkey_users\Administrateur\SOFTWARE\Solidworks», car il n'existe pas.
    Au caractère C:\Users\Administrateur\Desktop\rem_solidworks.ps1:7 : 2
    +  Remove-Item -Path hkey_users\$user\SOFTWARE\Solidworks -Recurse -For ...
    +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
    + CategoryInfo          : ObjectNotFound: (C:\Users\Admini...WARE\Solidworks:String) [Remove-Item], ItemNotFoundException    
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
    Translation: The process cannot access the file because it is in use. And then says that it cannot find the path for the RemoveItem, because the path is indeed wrong.

    Now this is expected for the Admin account as I'm logged on it to run the script, but it seems that the script doesn't try to load any other NTUSER after failing to load this one.

    Now I realise this has turned into practically strictly a Powershell question but still, any help would be appreciated.
      My Computers


  9. Posts : 989
    Microsoft Windows 10 Home
       #9

    fenrir0wulf said:
    Now I realise this has turned into practically strictly a Powershell question but still, any help would be appreciated.
    So please post the code you ran that generated the error!
    Last edited by KeithM; 04 Sep 2020 at 22:59.
      My Computer


  10. Posts : 43
    Windows 10 Pro Insider
    Thread Starter
       #10

    KeithM said:
    So plese post the code you ran that generated the error!
    Uuuhh, the code is already there. It's the exact one that was posted by RickC. The only difference is the software I want to delete. And Remove-Item since I want to delete the entire thing, subkeys and all, not just the key itself.

    Code:
    $users = (Get-ChildItem -path c:\users).name
    foreach($user in $users)
     {
     reg load "hku\$user" "C:\Users\$user\NTUSER.DAT"
     Remove-Item -Path "hkey_users\$user\SOFTWARE\Solidworks" /f
     reg unload "hku\$user"
     }
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 11:24.
Find Us




Windows 10 Forums