PASAf PASAf - 1 year ago 92 Question

How to close folders that in use by Explorer as it uninstallers do

I know most uninstallers of programs (at least since Windows 7) could delete program folder even if it opened up in Explorer. After uninstalling Explorer just refreshes and go up to Program Files folder automatically.

How to do same thing (tell explorer that folder need to be not in use) in programming language (particularly in

Answer Source

OK. So you want explorer to go to the parent folder of the current folder. If the current folder is "c:\windows\fonts", you want to change it to "c:\windows".

The following code should do this.. Have a look at the comments for an explanation of some of the code

    Private Sub ChangeExplorerToParentFolderOf(currentFolder As String)
    Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows
    Dim filename As String
    Dim operationCompleted As Boolean = False
    currentFolder = "file:///" & currentFolder.Replace("\", "/").ToLower
    'Searches all open explorer windows that are pointing to
    'the currentFolder parameter and if found, navigates to
    'its parent folder.
    'if successful, sets the operationCompleted cariable to true
    For Each ie As SHDocVw.InternetExplorer In shellWindows
        filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower()
        If filename.Contains("explorer") And ie.LocationURL.ToString.ToLower = currentFolder Then
            Dim parentFolder As String = currentFolder.Remove(currentFolder.LastIndexOf("/"))
            operationCompleted = True
        End If
    'If no instance of explorer is pointing to the currentFolder (operationCompleted=false),
    'show a messagebox to say so
    If operationCompleted = False Then
        MessageBox.Show("No instance of Windows Explorer exists that" & vbCrLf & "points to " & currentFolder)
    End If
End Sub
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download