Access is denied - when trying to get the url (text) from address bar's handle

前端 未结 1 1577
予麋鹿
予麋鹿 2021-01-18 21:06

I\'m trying to extract the URL from the address bar of IE. (IE 8 on Windows 7) using the following C# code.

        static string GetUrlFromIE()
        {
           


        
相关标签:
1条回答
  • 2021-01-18 21:42

    GetWindowText() can't retrieve the text of a control in another process, instead you should use SendMessage() with WM_GETTEXTLENGTH / WM_GETTEXT.

    Edit; Version agnostic way:

    (Add a ref to c:\WINDOWS\system32\shdocvw.dll)

    using SHDocVw;
    .
    .
    foreach (InternetExplorer ieInst in new ShellWindowsClass())
       Console.WriteLine(ieInst.LocationURL);
    
    0 讨论(0)
提交回复
热议问题