none
Script to clean HKEY_USERS RRS feed

  • Question

  • Hello, I currently have the foloowing issue.

    We are running citrix and when usrs sign in, their default printer resets to the local printers, (xps writer, send to one note, etc)

    This has been tracked down to the following Reistry Key HKEY_USERS 

    I have found a way that has fixed this issue for everyone who is experiencing it at my company.
    I had to go and edit the users registry hive:
    HKEY_USERS\USERS_SID_HERE\Printers\Connections
    I inevitably found old printer connections there that were no longer valid.  Upon clearing those out, after a reboot, the problem went away.
    I also cleared out the HKEY_USERS\USERS_SID_HERE\Printers\Settings key - the users had old printer setting sin there also.
    THANKS !!! This should be marked as the answer. 
    Checked HKEY_USERS\USERS_SID_HERE\Printers\Connections, found and old driver and deleted the driver. Everything is fine after restart.

    via https://social.technet.microsoft.com/Forums/windows/en-US/316fd408-4957-43b1-92e3-8dda96dcdded/default-printer-keeps-changing

    I manually deleted the Connections, and the Settings key and it went away. I am now trying to automate this as there are 25 servers with 400 users.

    this is a idea of a powershell script i was working on but I am lost.

    New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
    cd HKU:\
    Get-ChildItem "HKU:\" | Where-Object { $_.PSIsContainer }  | Remove-Item -Force -Recurse
    
    Get-ItemProperty -Path $_.PSPath -Name "DevModes2"
    Get-ItemProperty -Path $_.PSPath -Name "Settings"
    Get-ItemProperty -Path $_.PSPath -Name "Connections"

    the three Get-ItemProperty are the three folder i want to delete under HKEY_USERS

    can some one help?

    Note I also posted in the Server 2008 forum in-case there was another way to do this.

    Friday, May 8, 2015 8:39 PM

Answers

  • Just wanted to post a solution to the above problem with power shell

    New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
    cd HKU:\
    Get-ChildItem HKU:\*\Printers\DevModes2 -Recurse | Remove-Item -Confirm:$false
    Get-ChildItem HKU:\*\Printers\Connections -Recurse | Remove-Item -Confirm:$false
    Get-ChildItem HKU:\*\Printers\Settings -Recurse | Remove-Item -Confirm:$false
    

    This removes the folders in the registry for the users signed into this server and fixed their printer issue of resetting back to xps document writer.

    Citrix still has no working solution for our setup so this may help other people.

    Tuesday, May 26, 2015 5:02 PM

All replies

  • Hello, I currently have the foloowing issue.

    We are running citrix and when usrs sign in, their default printer resets to the local printers, (xps writer, send to one note, etc)

    This has been tracked down to the following Reistry Key HKEY_USERS 

    I have found a way that has fixed this issue for everyone who is experiencing it at my company.
    I had to go and edit the users registry hive:
    HKEY_USERS\USERS_SID_HERE\Printers\Connections
    I inevitably found old printer connections there that were no longer valid.  Upon clearing those out, after a reboot, the problem went away.
    I also cleared out the HKEY_USERS\USERS_SID_HERE\Printers\Settings key - the users had old printer setting sin there also.
    THANKS !!! This should be marked as the answer. 
    Checked HKEY_USERS\USERS_SID_HERE\Printers\Connections, found and old driver and deleted the driver. Everything is fine after restart.

    via https://social.technet.microsoft.com/Forums/windows/en-US/316fd408-4957-43b1-92e3-8dda96dcdded/default-printer-keeps-changing

    I manually deleted the Connections, and the Settings key and it went away. I am now trying to automate this as there are 25 servers with 400 users.

    this is a idea of a powershell script i was working on but I am lost.

    New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
    cd HKU:\
    Get-ChildItem "HKU:\" | Where-Object { $_.PSIsContainer }  | Remove-Item -Force -Recurse
    
    Get-ItemProperty -Path $_.PSPath -Name "DevModes2"
    Get-ItemProperty -Path $_.PSPath -Name "Settings"
    Get-ItemProperty -Path $_.PSPath -Name "Connections"

    the three Get-ItemProperty are the three folder i want to delete under HKEY_USERS

    can some one help?

    Friday, May 8, 2015 7:44 PM
  • Powershell forum is over here.

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverpowershell

     

     

     


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    Friday, May 8, 2015 8:12 PM
  • This is because Citrix is configured incorrectly.  Post in Citrix forum to find out how to configure so Citrix replaces the printers correctly.

    This can also be caused by incorrect Group Policy settings in a Citrix environment.

    You should not have to delete those keys.


    \_(ツ)_/

    Friday, May 8, 2015 9:17 PM
    Moderator
  • We do not use citrix to deploy the printers as most of our users print to different printers based on their current job.

    We have them add them through device and printers in the control panel, and they select them from the print server.

    Also there has been no change made to our citrix environment for over 6 months. Researching the issue points to old printers left in the users registry/ the citrix servers registry.

    I manually deleted the above paths and it solved the issue for the one user on the current server she was on.

    Friday, May 8, 2015 11:50 PM
  • I guess you know more than the rest of us about this.  Post your script and al error messages and we wil try to help you.

    \_(ツ)_/

    Saturday, May 9, 2015 12:50 AM
    Moderator
  • Here is my current script

    New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
    cd HKU:\
    Get-ChildItem -Path HKU:\ -Recurse -Include *DevModes2* | Remove-Item
    Get-ChildItem -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item
    Get-ChildItem -Path HKU:\ -Recurse -Include *Printers\Connections* | Remove-Item

    The first line is to map HKEY_USERS to the path of HKU

    then i cd into the mapped driver

    the next line removes the key DevModes2 this works. I have included the output. it has errors but I expect that.

    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *DevModes2* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\.DEF...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *DevModes2* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *DevModes2* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...417001333-10491:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *DevModes2* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *DevModes2* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    

    however the two lines below that I am trying to delete the keys located under Printers both settings and connections

    This does not work, I have included the output from PS

    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\.DEF...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...417001333-10491:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Requested registry access is not allowed.
    At line:1 char:14
    + Get-ChildItem <<<<  -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item
        + CategoryInfo          : PermissionDenied: (HKEY_USERS\S-1-...\ProtectedRoots:String) [Get-ChildItem], SecurityEx
       ception
        + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.GetChildItemCommand
    

    The error output does not seem to be from my script but more permissions issues as the script goes through each of the HKEY_USERS keys.

    What is the correct syntax to search for a key under a folder that you want to find via wildcard?

    eg here is the path of one of the users that is having the issue

    HKEY_USERS\S-1-5-21-725345543-1004336348-1417001333-10491\Printers\Settings

    I was hoping this command would work

    Get-ChildItem -Path HKU:\ -Recurse -Include *Printers\Settings* | Remove-Item

    Saturday, May 9, 2015 6:22 PM
  • What makes you think you can arbitrarily delete user keys.  I am not sure of why you want to d this kind of wild card delete across hives. It could be disastrous.

    If you want to remove a key you need to target a specific key and a specific hive. 

    Why would you do this?

    It is not clear what you are trying to do.  What key is it you want and why?


    \_(ツ)_/

    Thursday, May 21, 2015 2:13 AM
    Moderator
  • After studying and researching your issue fi a bit I am going to recommend what I have recommended to all other Citrix users who are having this issue.  Please contact Citrix support t have them show you the correct way to configure your printer deployment for Citrix.  By trying to use Windows simple solutions you are just complicating the Citrix management system.

    Remember that the Citrix print management kick in after the Windows print management setup.  You cannot really do an end run around it without creating problems.


    \_(ツ)_/

    Thursday, May 21, 2015 2:43 AM
    Moderator
  • If you want the full path to the keys I am trying to remove

    HKEY_USERS\THanson\Printers\Connections
    under this key are the following that will be removed when Connections is deleted

    ,,print1,CGY_HO_IT_HP_8150
    ,,print1,CGY_HO_IT_HP_8200
    ,,print1,CGY_HO_CU_HP_6300

    The next Key I am trying to remove is

    HKEY_USERS\THanson\Printers\Settings

    The last Key I wish to delete

    HKEY_USERS\THanson\Printers\DevModes2

    Thursday, May 21, 2015 3:53 AM
  • Ok, will also open a ticket with citrix.
    Thursday, May 21, 2015 3:54 AM
  • Just wanted to post a solution to the above problem with power shell

    New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
    cd HKU:\
    Get-ChildItem HKU:\*\Printers\DevModes2 -Recurse | Remove-Item -Confirm:$false
    Get-ChildItem HKU:\*\Printers\Connections -Recurse | Remove-Item -Confirm:$false
    Get-ChildItem HKU:\*\Printers\Settings -Recurse | Remove-Item -Confirm:$false
    

    This removes the folders in the registry for the users signed into this server and fixed their printer issue of resetting back to xps document writer.

    Citrix still has no working solution for our setup so this may help other people.

    Tuesday, May 26, 2015 5:02 PM
  • Hi Donald7777,

    Thanks for sharing the solution =)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Wednesday, May 27, 2015 8:46 AM
    Moderator
  • Just wanted to give you an example of what I use to delete SubKeys.  You can change the -like "*Keyname*" to what you want . After running this and making sure that it finds the keys that you want take the "#" off of #$regKey.DeleteSubKeyTree ($_); so that it will actually delete the keys 

    "Server = Xenapp1"
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $Xenapp1)
    "Removing Keys"
    $regKey = $reg.OpenSubKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\Client Side Rendering Print Provider', $true)
    $regKey.GetSubKeyNames() | Where{ $_ -like "*S*" } | ForEach {
      "Deleting subkey $_"
      #$regKey.DeleteSubKeyTree($_);
      }

    You should end up with something similar to this running the above.

    Server = Xenapp1
    Removing Keys
    Deleting subkey S-1-5-21-1856667356-3837370085-1058892159-3636
    Deleting subkey S-1-5-21-1856667356-3837370085-1058892159-4267
    Deleting subkey S-1-5-21-1856667356-3837370085-1058892159-4327
    Deleting subkey Servers


    • Edited by Joshua.Daniel Friday, June 5, 2015 9:37 PM changing the script.
    Friday, June 5, 2015 9:13 PM