I have searched but cannot find a function that can close a folder in vb.net. You can kill a running app by finding its handle/windows-title/id, then issuing process.kill() command, but the same does not work on folders. For example, suppose:
C:\\downloads\\videos\\
is open on my computer and I want to programmatically close it. How do I do that?
Make a folder in your c disk names Test
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myfolder As String = "C:\Test"
Dim OpenFolder As Object = CreateObject("shell.application")
For Each item In OpenFolder.Windows
'ComboBox1.Items.Add(item.document.folder.self.Path)
If item.document.folder.self.Path = myfolder Then
item.Quit()
End If
Next
End Sub
I see your dilemma: open folders are just one part of the explorer.exe
process. Killing that process would have undesirable side effects. To get around this, you have to send the right command to that process, instead of just killing it.
One place I would look to accomplish this is the SendKeys class. You might be able to focus the window and send the Alt-F4 keys to close just that window.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.