Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cleaning old file names from the registry 1

Status
Not open for further replies.

BadCook

Technical User
Sep 7, 2009
71
US
On opening VB6 the "Recent" file list contains the names of all the files recently worked on, including test or experimental files that have been deleted.
Can anyone suggest a macro that will remove these ghosts of departed programs from the Recent list?
I know one can go into the registry and delete the names but that is a mine field I would rather avoid.
Thanks for any suggestions.
 
This is (as far as I know) impossible to do without editing the registry (in some way).

Here are two ways (there will be more, and possibly shorter VB examples).

1: Using a VB exe (it has to be compiled to an exe as if you run it from the IDE the list will repopulate after you close VB)
Code:
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

Private Const ERROR_SUCCESS = 0&

Private Const KEY_CREATE_SUB_KEY = &H4&
Private Const KEY_SET_VALUE = &H2&
Private Const REG_SZ = 1
Private Const STANDARD_RIGHTS_WRITE = READ_CONTROL

Private Const KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY

Private Const HKEY_CURRENT_USER = &H80000001

Private Sub ClearRecentProjects()
Dim KeyVal&
Dim ret&
Dim SubKeyName$

SubKeyName$ = "Software\Microsoft\Visual Basic\6.0\RecentFiles"
   
    ret& = RegOpenKey(HKEY_CURRENT_USER, SubKeyName$, 0, KEY_WRITE, lphKey&)
    If ret& = ERROR_SUCCESS Then
        ret& = RegDeleteKey(lphKey&, "") 'delete the key
        ret& = RegCloseKey(lphKey&)
    End If
   
   ret& = RegCreateKey(HKEY_CURRENT_USER, SubKeyName$, KeyVal&)
   'ret& = RegSetValue(KeyVal&, vbNullString, REG_SZ, ByVal vbNullString, 0) ' not stricly necessary
   ret& = RegCloseKey(KeyVal&)
End Sub
Just call the sub ClearRecentProjects and it will delete the registry key that holds the recent projects and then re-create it with only the default value.

2: Use a batch file (this is in my opinion much easier but teachs you no VB [wink]). Create a text file and paste in the following:
Code:
@echo off
REG DELETE "HKCU\Software\Microsoft\Visual Basic\6.0\RecentFiles" /f
REG ADD "HKCU\Software\Microsoft\Visual Basic\6.0\RecentFiles"
msg "Your recent projects list has been cleared."
Save that file as WhateverYouWant.bat and then run it.

I would say that before you do anything with the registry that you should create a backup that you can restore any mistakes from (not that these will break your pc as I've tested them on my machine first). You can do this via Start-->Run regedit. From there click File-->Export and be sure to select the All radio but in Export Range at the bottom.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Thank you Harley for your responce.
I haven't studied your code yet, but tell me if your code cleans all the Recent files names or not.
What I intended to ask is for something that will remove specific names in the registry, not all of them.
I should have made that clear.
 
You should have posted this thread in forum222 because the subject concerns VB6 and not VBA, however;

The recently used list on the VB6 IDE may be considered a bit of a red herring because it is generally much more convienient to run the IDE over an existing project by double clicking its .vbp file in the project's folder in Windows Explorer. This has the added advantage of making the default CurDir$ for the project equal to the project folder; if you use the recently used file list CurDir$ will typically default to C:\Program Files\Microsoft Visual Studio\VB98, which is not very useful and may be a read only location under a limited account.
 
Yes, the code 'as is' will delete all entries in the recent files list.

If you do look at the code though it's pretty easy to modify it (well both of them) to only remove specific entries.

I am in agreement with Hugh though, it's generally easier not to use the recent files list and maintain links to the projects yourself.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top