var t = Type.GetTypeFromProgID("Shell.Application");
dynamic o = Activator.CreateInstance(t);
try
{
var ws = o.Windows();
for (int i = 0; i < ws.Count; i++)
{
var ie = ws.Item(i);
if (ie == null) continue;
var path = System.IO.Path.GetFileName((string)ie.FullName);
if (path.ToLower() == "explorer.exe")
{
string locationPath = ie.LocationURL;
}
}
}
finally
{
Marshal.FinalReleaseComObject(o);
}
3条答案
按热度按时间t3psigkw1#
以下是获取该信息的方法:
改编自:http://msdn.microsoft.com/en-us/library/windows/desktop/bb773974(v=vs.85).aspx
干杯
编辑:我将没有返回完整路径的
ie.locationname
更改为ie.document.focuseditem.path
,到目前为止似乎可以正常工作。nx7onnlm2#
以下是System.__ComObject的属性列表。
我改变了这代码上面像这样
即LocationURL返回打开窗口的路径
Look
3z6pesqy3#
如果你运行spy++和目标浏览器窗口,你会看到该窗口的标题或标题通常反映用户打开的当前目录
所以你需要的是使用窗口句柄你需要得到它的标题。我建议下面的链接将指导你
http://social.msdn.microsoft.com/Forums/vstudio/en-US/fd03235e-22af-41a4-aa95-2806b3cb1114/win32-getting-a-window-title-from-a-hwnd?forum=csharpgeneral
How to get the name of an External window in C# Application?