REGEDIT: Delete Current User keys with a little more ease

I’m terrible with traversing alphabetic directories; when I was in high school and I took the series of military aptitude tests, that was the only one I didn’t do well on. I excelled at the rest and the military did their best to court me. All I can say is that I’m one of the many potential recruits that they lost because of their dumb Don’t Ask, Don’t Tell policy. The recruiter told me they would overlook it but living the closeted life is not how I roll. Where am I going with this? Well, the Windows registry is a quadruple nightmare for me (and I’m sure a lot of others.) Any time I’m required to do something in it, I always try to automate the process. When anyone at my company is required to modify something in the registry at more than one workstation, I try to automate the process for them too.

Recently, after an NT to 2k3 domain migration, we had some old legacy keys that were causing problems; applications set in startup were opening twice. Unfortunately, they were under the HKCU (current user) key which is not available via Remote Registry or REG DELETE \machineName. Oh well, at least I could make a batch file for the Help Desk to double click while sitting at the user’s desk. We needed to delete keys valued 1 and 2 under the HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run key so we create a batch file which ran the following:

REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run /f /v 1
REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run /f /v 2

Alternatively, if we would have watned to delete everything under that Run key, we could have used the /va switch instead.

REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run /f /va

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, holds a master's degree in Systems Engineering and is coauthor of Learn dbatools in a Month of Lunches. Chrissy is certified in SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in Windows
2 comments on “REGEDIT: Delete Current User keys with a little more ease
  1. Derwood says:

    Don’t ask don’t tell was stupid anyway. The US military loses talented people every year to that stupid policy. It’s their loss. Maybe some day they will wake up and discover that sexual orientation has nothing to do with your ability to serve in the military.
    Oh, and as someone who spent 4 years in the military, I can tell you that you didn’t miss out on much ;-)

  2. Sean Tobin says:

    HI I’m trying to put some registrey codes on my laptop do you know where i could go and look at some keys that i could add to my laptop?



Leave a Reply

Your email address will not be published. Required fields are marked *