Script Request: Delete Registry Value

Dear Itarian Crew,

i have found a useful script here: https://scripts.itarian.com/frontend/web/topic/set-registry-value
it would however be very nice to have a script to delete an existing registry key.

Keep up the great work,
Thanks,
xfects

Hi @xfects,

Thanks for your script request. We have asked our script developers to provide the script.

Kind Regards,
PremJK

Hi @xfects,

Please run this script and provide your feedback on whether it suffice your needs
https://scripts.itarian.com/frontend/web/topic/delete-registry-value-or-registry-key

Kind Regards,
PremJK

Hello it likely works, however I think i might be not proficient enough with the registry values and so on to run it to my needs.
It would be lovely to have a script that executes multiple deletes in one go. My practical use case, for better understanding, is to remove clutter from the users explorer (3D Objects and so on) by deleting all of the values below. The scripts seems suitable for this, however is not very elegant to use for multiple keys :slight_smile: So some additional improvement would be really nice.

;3D Objects
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}]

;Documents
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{A8CDFF1C-4878-43be-B5FD-F8091C1C60D0}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{d3162b92-9365-467a-956b-92703aca08af}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{A8CDFF1C-4878-43be-B5FD-F8091C1C60D0}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{d3162b92-9365-467a-956b-92703aca08af}]

;Music
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{1CF1260C-4DD0-4ebb-811F-33C572699FDE}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{1CF1260C-4DD0-4ebb-811F-33C572699FDE}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de}]

;Pictures
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{3ADD1653-EB32-4cb0-BBD7-DFA0ABB5ACCA}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{24ad3ad4-a569-4530-98e1-ab02f9417aa8}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{3ADD1653-EB32-4cb0-BBD7-DFA0ABB5ACCA}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{24ad3ad4-a569-4530-98e1-ab02f9417aa8}]

;Videos
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{A0953C92-50DC-43bf-BE83-3742FED03C9C}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\MyComputer\NameSpace{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{A0953C92-50DC-43bf-BE83-3742FED03C9C}]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Explorer\MyComputer\NameSpa ce{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a}]

Hi @xfects,

Thanks for trying the script and providing improvement. We have shared your feedback with script developers and the updated script will be provided.

Kind Regards,
PremJK

Hi @xfects,

Please run this updated script and let us know if sufficed your needs
https://scripts.itarian.com/frontend/web/topic/delete-registry-value-or-registry-key

Kind Regards,
PremJK

The script was run as

import os
import ctypes
delete_type="RK"#RV-Registry value,RK-Registry Key
reg_path=[r'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsof t\Windows\CurrentVersion\Explorer\MyComputer\NameSpace',r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace']
reg_key=['{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}','{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}']

def reg_rv(reg_path,reg_key):
cmd='REG DELETE "%s" /v %s /f'%(reg_path,reg_key)
print cmd
return os.popen(cmd).read()
def reg_rk(reg_path):
cmd='REG DELETE "%s" /f'%(reg_path)
print cmd
return os.popen(cmd).read()

class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirect ion
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirecti on
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
with disable_file_system_redirection():
try:
if delete_type=="RK":
for i in reg_path:
reg_rk(i)
else:
for i in zip(reg_path,reg_key):
reg_rv(i[0],i[1])
except Exception as E:
print E

it deleted the whole structure HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace as opposed to only the key specified in the parameter “key”.

Hi @xfects,

When you use delete_type=“RK”, the whole Registry key will be deleted and if you use delete_type=“RV” when only the Registry value needs to be deleted.

Kind Regards,
PremJK

script works well, just the naming of the parameter-switch in conjunction with the value-parameters is confusing…
the reg_key parameter should in fact be the reg_value parameter then?