# Visual Basic > Visual Basic 6 and Earlier >  [RESOLVED] Unexpected Behavior Using CommonDialog ShowSave/ShowOpen Functions in VB6

## Timber

I recently took over long term maintenance of a Windows XP legacy application. When the original developers implemented the Backup/Restore functions using the "DriveListBox" dialogs, there were no issues with Windows (all versions) "Safely Remove Hardware and Eject Media" (I know this because I have all the prior version backups). Then they introduced the CommonDialog functions to identify and access drives other than the local disk (network shares/USB/etc.), the "Safely Remove Hardware and Eject Media" function reports the drive is still in use, shutdown the application accessing it. Is there a way to unbind or reset (to the local disk) the running application (in all reported cases it was a USB drive)?
    I've spent a reasonable amount of time using GOOGLE/BING searching for a solution; there are no references out there. If you have any ideas or pointers I would be most appreciative.


Specifics:
----------
C:\WINDOWS\system32\comdlg32.ocx
Disk Size: 156 KB (159,744 bytes)
Version: 6.1.98.16
Created: Tuesday, February 16, 2010, 2:22:44 PM


A code sample from the BACKUP function:
----------------------------------------------
Private Sub Form_Load()
'BACKUP Command Button
'
' For the CancelError=True property to function below, it is necessary to change the
'    VB6 IDE: Tools->Options->General: Error Trapping->"Break on all Errors" to
'    "Break on Unhandled Errors"
' It is also necessary to implement the "On Error" trap functions for each
'    COMMONDIALOG.SHOWSAVE calls
'
Dim fName As String
Dim a As Integer, d As Integer

On Error GoTo SaveErrMsg

fName = "BackUp-" & Format$(Now, "MMDDYYYY") & ".csv"

With CommonDialog1
    .fileName = ""
' Set starting location to: "My Computer"  This setting does not work on Windows 10
    .InitDir = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"   'CLSID for My Computer
    .CancelError = True
    .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist + cdlOFNHideReadOnly + cdlOFNExplorer
    .Filter = "Backup file (*.csv)|*.csv"
    .DialogTitle = "Save Backup File"
    .fileName = fName
    .ShowSave
End With

' MSGBOX events cannot be controlled by the Disable Sound Events setting
    MsgBox "Do Not modify the contents or rename the backup file" _
           , (vbInformation + vbApplicationModal + vbOKOnly), "BACKUP LIST"

Open CommonDialog1.fileName For Output As #3

    Write #3, "#", " -DO NOT- ", " -MODIFY- ", " -THIS- ", " -FILE- "

    -## Repetitive writes in a loop ##-

Close #3

    Exit Sub

SaveErrMsg:
        MsgBox "BACKUP LIST Dialog Canceled", _
        (vbExclamation + vbApplicationModal + vbOKOnly), "BACKUP LIST"
End Sub

----------


## k_zeon

try at 
https://www.tenforums.com/tutorials/...dows-10-a.html

sorry , just realised you used This PC.

----------


## Timber

k_zeon - Thank You for the pointer. I think I stumbled across this a while ago, but missed it in later review. Timber

----------


## Timber

After looking through the WIN32 API, trying to clear the MRU drive cache, writing a blank file to the TEMP folder; the solution turned out to be simple. Changing the active drive to the SYSTEMDRIVE environment variable after writing the BACKUP file allowed Windows (XP through 10) to successfully release the desired USB device. I hope this helps someone else going forward.

' RESET to the System Drive
Let fName = Environ("SystemDrive")
ChDrive fName

Timber

----------


## Elroy

I haven't seen a "Let" statement used in a while (as it's defaulted during assignments), but hey, I love the thoroughness.   :Smilie:

----------

