//FindWindow 查找窗口
//FindWindowEx查找子窗口
//EnumWindows列举屏幕上的所有顶层窗口,如果回调函数成功则返回非零,失败则返回零
//GetWindowText返回窗口的标题

一、首先要先导入要使用到的win api

[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern int EnumWindows(EnumWindowsProc hWnd, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpText, int nCount);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam); private const int WM_GETTEXT = 0x00D;
private static string _url; //定义委托 delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); static void Main(string[] args)
{
string url = GetWindowText(); Console.WriteLine(url);
Console.ReadKey(); } public static string GetWindowText()
{ IntPtr chrom = IntPtr.Zero;
EnumWindowsProc enwdproc = new EnumWindowsProc(FindChrom); if (EnumWindows(enwdproc, IntPtr.Zero) >= )
return _url;
else
return null;
} //回调函数
static bool FindChrom(IntPtr hWnd, IntPtr lParam)
{ var sb = new StringBuilder();
GetWindowText(hWnd, sb, sb.Capacity); if (sb.ToString() != String.Empty)
{
if (hWnd != IntPtr.Zero)
{
IntPtr tb = FindWindowEx(hWnd, new IntPtr(), "Chrome_OmniboxView", ""); //Chrome_OmniboxView是通过Spy++获得的 StringBuilder strbld = new StringBuilder();
SendMessage(tb, WM_GETTEXT, , strbld);
_url = strbld.ToString();
}
return false; }
//回调函数有返回值 return true; }

C# 调用win api获取chrome浏览器中地址的更多相关文章

  1. 在Chrome浏览器中保存的密码有多安全?

    本文由 伯乐在线 - 黄利民 翻译.未经许可,禁止转载!英文出处:howtogeek.欢迎加入翻译组. [2013-08-09 更新]:最近又开始讨论“Chrome浏览器明文保存密码这个话题了,国外一 ...

  2. 【js】IE、FF、Chrome浏览器中的JS差异介绍

    如何判断浏览器类型 转:http://www.cnblogs.com/carekee/articles/1854674.html 1.通过浏览器特有的对象 如ie 的ActiveXObject  ff ...

  3. 渗透技巧——导出Chrome浏览器中保存的密码

    0x00 前言 在后渗透阶段,获得权限后需要搜集目标系统的信息.信息越全面,越有助于进一步的渗透.对于Windows系统,用户浏览器往往包含有价值的信息. 在之前的文章<本地密码查看工具LaZa ...

  4. 导出Chrome浏览器中保存的密码

    title: 导出Chrome浏览器中保存的密码 date: 2018-02-11 17:54:51 tags: --- 导出Chrome浏览器中保存的密码 先知看到的,挺有意思,记录一下 不同浏览器 ...

  5. Google Chrome浏览器中如何使用命令

    Google Chrome浏览器中如何使用命令 | 浏览:2974 | 更新:2014-02-23 23:12 | 标签:chrome 1 2 3 分步阅读 Google Chrome浏览器有很多的特 ...

  6. 调用ZoomEye API获取信息

    最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块urllib,json,os模块. 功能:调用ZoomEye API获取信息 import urllib.requ ...

  7. 去掉chrome浏览器中input获得焦点时的带颜色边框呢

    可以设置表单控件的outline属性为none值, 来去掉Chrome浏览器中输入框以及其它表单控件获得焦点时的带颜色边框. css代码如下: input{outline:none}

  8. [转]chrome浏览器中 F12 功能的简单介绍

    本文转自:https://www.cnblogs.com/zhuzhubaoya/p/9758648.html chrome浏览器中 F12 功能的简单介绍 由于F12是前端开发人员的利器,所以我自己 ...

  9. 查看 chrome 浏览器中的 Headers

    查看 chrome 浏览器中的 Headers, Response 信息:

随机推荐

  1. Java监听模式

    说明 生活中,监听无处不在.比如说,手机播放音乐功能,也是一种监听:你不点击播放按钮,手机就不放歌,当你点击时,手机就播放音乐.即触发某种行为,便执行相应的动作. 组成 Java监听模式右三个部分组成 ...

  2. PHP案例:学生信息管理系统

    -- Database: test -- 表的结构 message CREATE TABLE `message` ( `id` tinyint(1) NOT NULL PRIMARY KEY AUTO ...

  3. 类似Unity的全新游戏引擎Godot

    http://www.godotengine.org/wp/ Godot是一个全新开发的游戏引擎,其功能集类似知名的跨平台游戏引擎Unity,可用于开发PC.主机.移动和Web游戏.开发者声称引 擎的 ...

  4. Centos版本 32或64位查看命令

    [root@root nginx]# uname -a Linux root -.el6.x86_64 # SMP Fri Nov :: UTC x86_64 x86_64 x86_64 GNU/Li ...

  5. Control character in cookie value or attribute

    在cookie中添加中文导致静态页面打不开, (1)先清除缓存 (2)使用escape()函数对中文进行编码,获取的时候在对中文进行解码unescape(). cookie.Set("sto ...

  6. 常见sql 写法总结

    关于如何获取1对多数据中最大条数据的写法 例子: LEFT JOIN ( SELECT * FROM table AS n1 WHERE n1.ID IN ( SELECT MAX(id) FROM ...

  7. 第二百一十六节,jQuery EasyUI,Spinner(微调)组件

    jQuery EasyUI,Spinner(微调)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个 ...

  8. 【ARIMA】Autoregressive Integrated Moving Average Model

    [理论部分] ARIMA包含两部分,自回归AR和移动平均MA: AR:Y(t)-a=b(1){Y(t-1)-a}+u(t)   其中a是y的均值, u(t)是均值为零,恒定方差的不相关随机误差项(噪声 ...

  9. 【bzoj4518】[Sdoi2016]征途 斜率优化dp

    原文地址:http://www.cnblogs.com/GXZlegend/p/6812435.html 题目描述 Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界 ...

  10. iOS 下载

    #import "ViewController.h" @interface ViewController () @property (strong, nonatomic) NSMu ...