@@ -11,6 +11,7 @@ def create_sub_command(name, desc, command, icon):
1111 else :
1212 winreg .SetValueEx (key , "Icon" , 0 , winreg .REG_SZ , "" )
1313 winreg .SetValueEx (key , "direct" , 0 , winreg .REG_SZ , "Yes" )
14+ key .Close ()
1415
1516def create_sub_group (name , desc , icon , coms ):
1617 key = winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE ,'Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ CommandStore\\ shell' ,0 ,winreg .KEY_ALL_ACCESS | winreg .KEY_WOW64_64KEY )
@@ -22,6 +23,8 @@ def create_sub_group(name, desc, icon, coms):
2223 winreg .SetValueEx (comKey , "Icon" , 0 , winreg .REG_SZ , icon )
2324 else :
2425 winreg .SetValueEx (comKey , "Icon" , 0 , winreg .REG_SZ , "" )
26+ key .Close ()
27+ comKey .Close ()
2528
2629def create_group (name , desc , filetype , icon , coms ):
2730 key = winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , "SystemFileAssociations\\ " + filetype + "\\ shell" )
@@ -32,6 +35,8 @@ def create_group(name, desc, filetype, icon, coms):
3235 winreg .SetValueEx (comKey , "Icon" , 0 , winreg .REG_SZ , icon )
3336 else :
3437 winreg .SetValueEx (comKey , "Icon" , 0 , winreg .REG_SZ , "" )
38+ key .Close ()
39+ comKey .Close ()
3540
3641def create_command (name , desc , command , filetype , icon ):
3742 key = winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , "SystemFileAssociations\\ " + filetype + "\\ shell" )
@@ -41,6 +46,8 @@ def create_command(name, desc, command, filetype, icon):
4146 winreg .SetValue (comKey , "Icon" , winreg .REG_SZ , icon )
4247 winreg .CreateKey (comKey , "command" )
4348 winreg .SetValue (comKey , "command" , winreg .REG_SZ , command )
49+ key .Close ()
50+ comKey .Close ()
4451
4552def get_file_types ():
4653 keys = {}
@@ -61,25 +68,37 @@ def get_file_types():
6168 return keys
6269
6370def remove_file_association (filetype , name ):
64- key = winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , "SystemFileAssociations\\ " + filetype + "\\ shell" )
65- comKey = winreg .CreateKey (key , name )
66- remove_all_sub_keys (comKey )
67- winreg .DeleteKey (key , name )
71+ try :
72+ key = winreg .CreateKey (winreg .HKEY_CLASSES_ROOT , "SystemFileAssociations\\ " + filetype + "\\ shell" )
73+ comKey = winreg .CreateKey (key , name )
74+ remove_all_sub_keys (comKey )
75+ comKey .Close ()
76+ winreg .DeleteKey (key , name )
77+ key .Close ()
78+ except WindowsError :
79+ pass
6880
6981def remove_command_store (name ):
70- key = winreg .CreateKey (winreg .HKEY_LOCAL_MACHINE , "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ CommandStore\\ shell" )
71- comKey = winreg .CreateKey (key , name )
72- remove_all_sub_keys (comKey )
73- winreg .DeleteKey (key , name )
82+ try :
83+ key = winreg .CreateKey (winreg .HKEY_LOCAL_MACHINE , "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ CommandStore\\ shell" )
84+ comKey = winreg .CreateKey (key , name )
85+ remove_all_sub_keys (comKey )
86+ comKey .Close ()
87+ winreg .DeleteKey (key , name )
88+ key .Close ()
89+ except WindowsError as e :
90+ print (e )
7491
7592def remove_all_sub_keys (key ):
7693 index = 0
7794 length = winreg .QueryInfoKey (key )[0 ]
78- for i in range ( 0 , length ) :
95+ while length > 0 :
7996 try :
80- subname = winreg .EnumKey (key , i )
97+ subname = winreg .EnumKey (key , 0 )
8198 subkey = winreg .CreateKey (key , subname )
8299 remove_all_sub_keys (subkey )
100+ subkey .Close ()
101+ length -= 1
83102 winreg .DeleteKey (key , subname )
84103 except OSError as e :
85- pass
104+ print ( e )
0 commit comments