Mega Code Archive

 
Categories / Delphi / Forms
 

How to delete the MRU (history) lists from the Open and Save dialogs

Title: How to delete the MRU (history) lists from the Open and Save dialogs Question: How can you delete the MRU (most recently used) filename lists from the Open and Save dialog boxes. Answer: The MRU lists for the Open and Save dialogs are stored in the registry. You may want to delete these for security reasons. Each file type has it's own set of MRU filenames, for example the Word filenames are stored at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\doc There can be up to 10 filenames stored as "a" thru "j" (Default) (not set) a c:\temp\cv.doc b c:\Documents and Settings\bromleyl\Shopping List.doc ... i c:\temp\another.doc j c:\temp\final.doc and then an entry to order the entries MRUList jihbfedacg To delete MRUs for one file type use the procedure below, e.g. DeleteMRU('xls') Uses ....Registry; Const MRUKeyRoot = 'Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\'; procedure DeleteMRU(const keyname:String); var Reg : TRegistry; I : Integer; begin Reg:=TRegistry.Create(); try Reg.RootKey:=HKey_Current_User; if Reg.OpenKey(MRUKeyRoot + keyname,False) then begin for I:=1 to 10 do begin {delete the values a thru i} Reg.DeleteValue(Chr(96 + I)); end; {and clear out the order string} Reg.WriteString('MRUList',''); Reg.CloseKey; end; finally Reg.Free; end; end; To delete all MRUS you can use the GetKeyName function and cycle thru all the file types procedure DeleteAllMRUs; var M : Integer; Reg : TRegistry; AllMRUs : TStringList; procedure DeleteMRU(Reg : TRegistry; const keyname:String); var I : Integer; begin Reg.RootKey:=HKey_Current_User; if Reg.OpenKey(MRUKeyRoot + keyname,False) then begin for I:=1 to 10 do begin Reg.DeleteValue(Chr(96 + I)); end; Reg.WriteString('MRUList',''); Reg.CloseKey; end; end; begin Reg:=TRegistry.Create(); try Reg.RootKey:=HKey_Current_User; AllMRUs:=TStringList.Create; try if Reg.OpenKey(MRUKeyRoot,False) then begin Reg.GetKeyNames(AllMRUs); Reg.CloseKey; for M:=0 to AllMRUs.Count -1 do DeleteMRU(Reg,AllMRUs.Strings[M]); end; finally AllMRUs.Free; end; finally Reg.Free; end; end;