dcsimg
Results 1 to 16 of 16

Thread: [RESOLVED] 'Recent Files' backup and restore

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Resolved [RESOLVED] 'Recent Files' backup and restore

    This might seem an odd thread but every so often I find I lose some or even most of the list of my projects in 'Recent Files'. Sometimes I get into the registry and find that the numbers associated with the projects are no longer contiguous so I correct them and the full list returns.
    However, just this morning I noticed that the list contained only four items and when I checked the registry I found that all the others had been lost.
    I have occasionally thought of tackling the problem myself but have to admit that I am a little anxious about writing code that involves the registry - for obvious reasons.
    Has anyone written a VB6.0 program to backup and restore those lists?
    My O/S is Win10 64-bit Professional. Thanks in advance.

  2. #2
    Addicted Member
    Join Date
    Aug 2017
    Posts
    136

    Re: 'Recent Files' backup and restore

    The easiest and safest way is probably by shelling regedit.exe and telling it to import/export a .REG file that contains the values under HKCU\Software\Microsoft\Visual Basic\6.0\RecentFiles.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,572

    Re: 'Recent Files' backup and restore

    I almost never even look at the recent files list. Most, almost all of the time I start Vb by clicking on the vbp I want to work on or just vb if I intend to start a new project. I can't even remember the last time I clicked on the recent files menu item to see what was there.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,343

    Re: 'Recent Files' backup and restore

    Same here.

    I wouldn't even trust it, since I don't use a GUID Generator to create unique Project names.

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Re: 'Recent Files' backup and restore

    Many thanks for all your comments. When I used WinXP, I downloaded an app that allowed me to save the positions of all the icons on my desktop so that, if I changed the screen resolution for some reason and the icons moved, I could restore them to their original positions. It worked well. I guess I'm after something similar, such as a program with a form containing just two buttons. Nevertheless I'll look at your suggestion, Victor, and thanks.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,882

    Re: 'Recent Files' backup and restore

    here is a simple example to read the recent files registry and write a .reg file that can be used to restore, as i would expect restoring to be very occasional, it could be done manually (merging the .reg file) or shelling from vb if desired, i only did code to make the backup

    Code:
    Sub getrecent()
          Dim objRegistry As Object, i As Integer, f As Integer, regath As String
            regpath = "HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0\RecentFiles\"
    
            Set objRegistry = CreateObject("Wscript.shell")
            f = FreeFile
            Open "c:\temp\vb6recent" & Format(Date, "yyyymmdd") & ".reg" For Output As f
            Print #f, "Windows Registry Editor Version 5.00" & vbNewLine
            For i = 1 To 50
                Print #f, """" & i & """ = """ & objRegistry.RegRead(regpath & i) & """"""
            Next
            Close f
    End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,843

    Re: 'Recent Files' backup and restore

    Truth be told, I do often use the MRU lists. However, since Windows 10, I tend to use those MRU lists rather than the lists specific to any software program (such as the VB6 IDE).

    However, as stated above, I'm always very careful with it, always somehow checking the folder from which it found the file.

    And, because these MRU lists can become corrupt, I have a batch file that does the opposite of what you suggest. It just deletes all those Windows 10 shortcuts. Whether in the registry, or just created shortcuts, I don't see how trying to back them up is going to accomplish anything. For specific programs, there's no specific scheme for tracking these. And, for specific programs or just Windows 10, these lists are going to be so volatile and dynamic that it will be difficult to make any sense of a snapshot backup.

    Personally, I just try to do a good job of keeping all my "actual" files organized so I can find them when I need them.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Re: 'Recent Files' backup and restore

    Thanks again for your comments. Regarding a suggestion that my VB projects might not be organised, I have them all in a special partition on my SSD so I can easily find them BUT it is a little time-consuming to navigate through all the folders - particularly as I sometimes work on two or three projects at the same time - so in that regard I find the 'Recent' option very convenient.
    Thank you westconn1 for the code you've provided. I'll check that out. (I've assumed that in the dimensioning of variables, the last string should be regpath)

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,572

    Re: 'Recent Files' backup and restore

    I have the bulk of my projects stored as \SourceCode\Clients\ClientName\ProjectName

    A shortcut to the clients folder makes it fairly quick and easy to get to any project I am wanting to work on.

    Of course there are other folders in that source folder other than clients, I have folders for sample code, in house utilities and so on.
    All required files are always stored in the project folder or subfolder of it so that I can easily copy the project or any number of projects to a different drive or PC without issues. Been doing it this way for many years now and seems to work well for me.

    Recent files would not be a lot of help to me as it would often just have links to project1 or form1 or module1 from some quick test I did and not ave the list of real projects I would be needing.

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Re: 'Recent Files' backup and restore

    I've always been a bit reluctant to place folder shortcuts on my desktop. Don't ask me why.

    I've tried out your code, westconn1, but I'm afraid I'm getting a run-time error, informing me that the registry key to the recentfiles cannot be opened. I've noted that the number of projects listed in 'Recent' is being correctly added to the RegPath string after the last backslash. (I've made a few cosmetic changes to your code just to conform to my usual VB programming practice. It won't affect code execution in any way). I've also noticed that after entering regread (entered all in lower case) the two 'rs' did not change to upper case as expected and I am
    always suspicious when that happens. (I checked up on that property and the elderly Help I've installed states that it is a Windows Script Host topic and is part of a beta release. My VB6.0 is fully updated to SP6, by the way). Finally, I don't understand what all those sets of inverted commas do inside the Print loop? I hope you can clear that up for me. I've checked my code for typos and didn't find any.

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Re: 'Recent Files' backup and restore

    I've always been a bit reluctant to place folder shortcuts on my desktop. Don't ask me why.

    I've tried out your code, westconn1, but I'm afraid I'm getting a run-time error, informing me that the registry key to the recentfiles cannot be opened. I've noted that the number of projects listed in 'Recent' is being correctly added to the RegPath string after the last backslash. (I've made a few cosmetic changes to your code just to conform to my usual VB programming practice. It won't affect code execution in any way). I've also noticed that after entering regread (entered all in lower case) the two 'rs' did not change to upper case as expected and I am
    always suspicious when that happens. (I checked up on that property and the elderly Help I've installed states that it is a Windows Script Host topic and is part of a beta release. My VB6.0 is fully updated to SP6, by the way). Finally, I don't understand what all those sets of inverted commas do inside the Print loop? I hope you can clear that up for me. I've checked my code for typos and didn't find any.

  12. #12
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,572

    Re: 'Recent Files' backup and restore

    I also avoid folder shortcuts for the most part but I do have the one for my code folder and of course a link to explorer on the quick launch. Over the years I have experimented with different methods. I have created a folder on the disk and placed shortcuts into that folder and then made that folder a link on the start menu, in the system tray, in the quick launch and on the desktop. Not all at once of course but have toyed with the various locations to see what felt best. Most of the time I simply click on explorer and open the folder I need.

  13. #13

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Re: 'Recent Files' backup and restore

    I guess in computing we all discover the most convenient ways of doing things over time and tend to stick with them.
    Because of the error message, I didn't think to check the c:\temp folder but I now know that a 2KB REG file is there, so I guess I have to assume that the RecentFiles registry key has been saved.

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,882

    Re: 'Recent Files' backup and restore

    Finally, I don't understand what all those sets of inverted commas do inside the Print loop?
    i did an export from the registry then copied the format exactly

    as regread is method of a variable defined as object, no intellisense or case changes would occur, you can add a reference to windows scripting host and define the objects with appropriate types as in early binding

    as there were 50 entries in my registry i worked on the assumption that was the default, but in the case of less entries an error would occur, i should have error handled that case

    i did test the code before posting, and had a matching file to the one exported manually

    here is an alternative soution
    Code:
          Dim filepath As String, regpath As String
            regpath = "HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0\RecentFiles"
    
            filepath = "c:\temp\vb6recent" & Format(Date, "yyyymmdd") & ".reg"
            Shell "regedit.exe /E " & filepath & " """ & regpath & """"
    Last edited by westconn1; Dec 10th, 2018 at 05:30 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15
    Addicted Member
    Join Date
    Aug 2017
    Posts
    136

    Re: 'Recent Files' backup and restore

    Quote Originally Posted by westconn1 View Post
    here is an alternative soution
    Yes, that is what I was suggesting in post #2.

  16. #16

    Thread Starter
    Member
    Join Date
    Nov 2013
    Posts
    52

    Re: 'Recent Files' backup and restore

    Thanks for the code update, westconn1. I'll check it out. I admit I did look at the upper value for the loop and wondered if that might have had something to do with the error as I don't think I've ever had 50 projects in my 'Recent' lists.
    I think I'll call it a day now, so thanks for everybody who assisted with ideas.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width