Posts Tagged API

VB管道操作

Posted by on 星期四, 7 四月, 2011

Visual Basic的管道操作,用于与控制台程序、DOS命令等命令行接口的程序通信,能清楚地知道命令执行情况。

源码下载:>>本地下载<<

ros winbox api 应用

Posted by on 星期五, 18 二月, 2011

winbox api VB.net 类库:cls_Mikrotik.vb

代码:

Dim mk = New Mikrotik("192.168.0.1")
Dim strUsername As String, strGrid() As String
If Not mk.Login("admin", "Mikrotik_hhsoft") Then
mk.Close()
Return
End If

mk.Send("/ppp/active/print", True)
For Each row In mk.Read()
If InStr(row, "!done") = 0 Then
strGrid = Split(row, "=")
Console.WriteLine(strGrid(4) & vbTab & vbTab & strGrid(12))
End If
Next

返回的数据包:

!re=.id=*139=name=malidan=service=pppoe=caller-id=00:11:43:57:B9:0F=address=172.16.0.108=uptime=00:22:14=encoding==session-id=2167406760=limit-bytes-in=0=limit-bytes-out=0=radius=true
!re=.id=*13A=name=zhaoliang=service=pppoe=caller-id=00:E0:4D:A5:B2:5E=address=172.16.0.107=uptime=00:13:41=encoding==session-id=2167406761=limit-bytes-in=0=limit-bytes-out=0=radius=true
!done


网众快车自动登录器

Posted by on 星期三, 14 七月, 2010

网众快车自动登录器 – 单击下载

用于网众快车服务端的自动登录。

用VB写的,相关代码:


Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean ‘枚举窗口
On Error Resume Next
Dim sTitle As String
Dim hrect As RECT
sTitle = String(80, 0)
Call GetWindowText(hwnd, sTitle, 80) '获取标题
sTitle = left(sTitle, InStr(sTitle, Chr(0)) - 1)
If Len(sTitle) > 0 And sTitle = "用户登录" Then ’如果标题为“用户登录”,则找到窗口
GetWindowRect hwnd, hrect '获得窗口的位置
coLoginWindow.hwnd = hwnd
coLoginWindow.left = hrect.left
coLoginWindow.top = hrect.top
End If
DoEvents
EnumWindowsProc = True
End Function
Private Function EnumChildWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean '枚举子窗口
On Error Resume Next
Dim hrect As RECT
Dim strCaption As String * 255
GetWindowRect hwnd, hrect

If (hrect.left - coLoginWindow.left = 116) And (hrect.top - coLoginWindow.top = 52) Then coUsername.hwnd = hwnd '如果找到指定位置的窗口
If (hrect.left - coLoginWindow.left = 116) And (hrect.top - coLoginWindow.top = 81) Then coPassword.hwnd = hwnd
If (hrect.left - coLoginWindow.left = 104) And (hrect.top - coLoginWindow.top = 177) Then coLogin.hwnd = hwnd

GetWindowText hwnd, strCaption, Len(strCaption)

DoEvents
EnumChildWindowsProc = True

End Function

Public Function GethWnd() As Long '调用枚举窗口和子窗口的过程
EnumWindows AddressOf EnumWindowsProc, 0&
DoEvents
EnumChildWindows coLoginWindow.hwnd, AddressOf EnumChildWindowsProc, 0&
End Function

Public Sub SendText(strUsername As String, strPassword As String) '像窗口发送用户名密码
Dim i As Integer
SendMessage coUsername.hwnd, WM_ACTIVATE, 0&, 0& '激活窗口
SendMessage coUsername.hwnd, WM_LBUTTONDBLCLK, 0&, 0& '双击窗口
SetForegroundWindow coLoginWindow.hwnd '窗口提前

For i = 1 To Len(strUsername) '循环总共 Len(strUsername) 次
Delay 10, True '等10/1000秒
KeyUPDOWN Asc(UCase(Mid(strUsername, i, 1))), coUsername.hwnd '发送按键消息
Next i
KeyUPDOWN vbKeyTab, coLoginWindow.hwnd '按一次TAB键

Delay 100, True
For i = 1 To Len(strPassword)
Delay 10, True
KeyUPDOWN Asc(UCase(Mid(strPassword, i, 1))), coPassword.hwnd
Next i
End Sub
Private Sub KeyUPDOWN(lKey As Long, rhWnd As Long) '发送按键过程
Dim lParam As Long
lParam = makelparam(lKey, False) '生成lparam参数,按下
PostMessage rhWnd, WM_KEYDOWN, lKey, lParam '发送按键消息
DoEvents
lParam = makelparam(lKey, True)'生成lparam参数,弹起
PostMessage rhWnd, WM_KEYUP, lKey, makelparam(lKey, True)
End Sub
Private Function makelparam(ByVal VirtualKey As Long, ByVal flag As Boolean) As Long '生成lparam参数过程
Dim s As String
Dim Firstbyte As String 'lparam参数的24-31位
If flag = False Then 'keydown
Firstbyte = "00"
Else
Firstbyte = "C0" 'keyup
End If
Dim Scancode As Long
'获得虚拟键扫描码
Scancode = MapVirtualKey(VirtualKey, 0)
Dim Secondbyte As String 'lparam参数的16-23位,即虚拟键扫描码
Secondbyte = Right("00" & Hex(Scancode), 2)
s = Firstbyte & Secondbyte & "0001" '0001为lparam参数的0-15位,即发送次数
makelparam = Val("&H" & s)
End Function

Public Sub ClickLogin() '单击“登录”按钮
SendMessage coLogin.hwnd, WM_ACTIVATE, 0&, 0& '激活登录按钮
SetForegroundWindow coLogin.hwnd '按钮提前
PostMessage coLogin.hwnd, WM_LBUTTONDBLCLK, 0, 0 '双击按钮,不知道为什么,用单击不好使-_-||
DoEvents
End Sub

Public Sub Delay(lTimes As Long, Optional bSleep As Boolean) '自定义的延时过程
Dim l As Long
For l = 0 To lTimes
DoEvents
If bSleep = True Then Sleep 1
Next l
End Sub