获取资源管理器中所有打开的文件夹 [英] Get all open folders in explorer
本文介绍了获取资源管理器中所有打开的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在7到10的所有Windows版本中获取Windows资源管理器中打开的文件夹和目录列表?
在C#或VB.Net中
我尝试过:
< pre>导入Shell32 添加参考浏览C:\ WindowsTD32或#Shell32.dll或com Microsoft Shell控件和自动化
' http://xkom.blogspot.com/2011/06/get-opened- folder-location-in-explorer.html
公共 类 Form1
Dim Lb As 新 ListBox
Dim WithEvents RoutineTimer As 新计时器
私有 Sub Form1_Load(发件人) 作为 对象,e 作为 EventArgs)< span class =code-keyword>句柄 MyBase .Load
Lb.Parent = 我
Lb.Dock = DockStyle.Fill
我 .Text = 按用户打开文件夹(资源管理器)
RoutineTimer.Interval = 1000
RoutineTimer.Start()
结束 Sub
Sub GetOpenedFolder()
Dim MShell 作为 新 Shell
Dim SFV As ShellFolderView
Lb.Items.Clear()
开 错误 < span class =code-keyword> Resume Next
对于 每个 o 在 MShell.Windows
如果 TypeName(o.document)<> HTMLDocument 然后
SFV = o.document
如果 SFV.Folder.Items.Count> 0 然后
Lb.Items.Add(TrimPath( CType (SFV.Folder.Items( 0 ),ShellFolderItem).Path))
结束 如果
结束 如果
下一步
结束 Sub
Sub Timer_Job() Handles RoutineTimer.Tick
GetOpenedFolder()
结束 Sub
功能 TrimPath( ByRef s As 字符串) As String
返回 s。删除(InStrRev(s, \))
结束 功能
结束 类
我在Windows 7上使用此功能但在Windows 10上没有工作
解决方案
检查: winapi - 如何使用C#查找所有窗口? - 堆栈溢出 [ ^ ]
How to get the list of open folders and directories in windows explorer in all windows versions from 7 to 10?
in C# or VB.Net
What I have tried:
<pre>Imports Shell32 ' Add reference browse C:\Windows\System32\Shell32.dll or com Microsoft Shell Controls and Automation
'http://xkom.blogspot.com/2011/06/get-opened-folder-location-in-explorer.html
Public Class Form1
Dim Lb As New ListBox
Dim WithEvents RoutineTimer As New Timer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Lb.Parent = Me
Lb.Dock = DockStyle.Fill
Me.Text = "Opened Folder by user (explorer)"
RoutineTimer.Interval = 1000
RoutineTimer.Start()
End Sub
Sub GetOpenedFolder()
Dim MShell As New Shell
Dim SFV As ShellFolderView
Lb.Items.Clear()
On Error Resume Next
For Each o In MShell.Windows
If TypeName(o.document) <> "HTMLDocument" Then
SFV = o.document
If SFV.Folder.Items.Count > 0 Then
Lb.Items.Add(TrimPath(CType(SFV.Folder.Items(0), ShellFolderItem).Path))
End If
End If
Next
End Sub
Sub Timer_Job() Handles RoutineTimer.Tick
GetOpenedFolder()
End Sub
Function TrimPath(ByRef s As String) As String
Return s.Remove(InStrRev(s, "\"))
End Function
End Class
I used this on windows 7 but not working on windows 10
解决方案
Check this: winapi - How do I find all windows using C#? - Stack Overflow[^]
这篇关于获取资源管理器中所有打开的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文