?? clsclient.vb
字號:
'****************************************************************************
'人人為我,我為人人
'枕善居漢化收藏整理
'發布日期:2007/07/23
'描 述:網吧計費管理系統客戶端/服務器端
'網 站:http://www.Mndsoft.com/ (VB6源碼博客)
'網 站:http://www.VbDnet.com/ (VB.NET源碼博客,主要基于.NET2005)
'e-mail :Mndsoft@163.com
'e-mail :Mndsoft@126.com
'OICQ :88382850
' 如果您有新的好的代碼別忘記給枕善居哦!
'****************************************************************************
Imports System.Net.Sockets
Imports System.Text
Imports System.Management
Public Class ClsClient
Private Client As TcpClient
Const PORTNUM As Integer = 10000
Const READ_BUFFER_SIZE As Integer = 255
Dim readbuffer(READ_BUFFER_SIZE) As Byte
Public ComputerName As String 'MAC 地址
Public ClientIPAddress As String
Public ServerIPAddress As String = "127.0.0.1"
Sub New()
Dim Adapters As New ArrayList
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If CBool(mo.Item("IPEnabled")) Then
Dim strAdapter As String
strAdapter = mo.Item("Caption").ToString().Substring(11)
Adapters.Add(strAdapter)
End If
Next
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
For Each mo In moc
If CBool(mo.Item("IPEnabled")) Then
Dim strAdapter As String
strAdapter = mo.Item("Caption").ToString().Substring(11)
If strAdapter = Adapters(0) Then
ComputerName = mo.Item("MacAddress").ToString()
End If
End If
Next
Dim Address() As System.Net.IPAddress
Address = System.Net.Dns.GetHostByName(SystemInformation.ComputerName).AddressList
ClientIPAddress = Address(0).ToString
End Sub
Public Sub ConneceAndRead()
Try
Client = New TcpClient(ServerIPAddress, PORTNUM)
Client.GetStream.BeginRead(readbuffer, 0, READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub DoRead(ByVal ar As IAsyncResult)
Dim message As String
Dim bytesread As Integer
bytesread = Client.GetStream.EndRead(ar)
message = Encoding.ASCII.GetString(readbuffer, 0, bytesread)
ProcessCommand(message)
client.GetStream.BeginRead(readbuffer, 0, READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
End Sub
Sub ProcessCommand(ByVal data As String)
Dim dataArray() As String
dataArray = data.Split(",")
Select Case dataArray(0)
Case "LOGIN"
If Val(dataArray(1)) = 1 Then
MsgBox("登錄成功")
End If
If Val(dataArray(1)) = 0 Then
MsgBox("用戶名或者密碼錯誤")
End If
If Val(dataArray(1)) = -1 Then
MsgBox("余額不足請及時充值!")
End If
Case "LOGOFF"
If Val(dataArray(1)) > 10 Then
MsgBox("退出成功!余額為" & dataArray(1))
Else
MsgBox("退出成功!余額為" & dataArray(1) & ",請及時加款!")
End If
Case "BROADCAST"
If Trim(dataArray(1)) <> "" Then
MsgBox(dataArray(1))
Else
ShutDown()
End If
End Select
End Sub
Public Sub SendData(ByVal data As String)
Dim writer As New IO.StreamWriter(client.GetStream)
writer.Write(data & Chr(13) & Chr(10))
writer.Flush()
End Sub
Shared Sub ShutDown()
System.Diagnostics.Process.Start("Shutdown", "/r") 'to restart
' System.Diagnostics.Process.Start("Shutdown", "/l") 'to logoff
' System.Diagnostics.Process.Start("Shutdown", "/a") 'to abort
' System.Diagnostics.Process.Start("Shutdown", "/s") 'to abort
End Sub
Shared Sub LockComputer()
Dim key, subkey As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser
subkey = key.OpenSubKey("software\microsoft\windows\currentversion\policies\system", True)
subkey.SetValue("DisableRegistryTools", 1)
subkey.Close()
'禁用注冊表
subkey = key.OpenSubKey("software\microsoft\windows\currentversion\policies\system", True)
subkey.SetValue("DisableTaskMgr", 1)
subkey.Close()
'屏蔽任務管理器
End Sub
Shared Sub AutoStart()
'設置開機后客戶端自啟動
Dim key, subkey As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser
subkey = key.OpenSubKey("software\microsoft\windows\currentversion\run", True)
subkey.SetValue("Client", Application.StartupPath + "\Client.exe")
subkey.Close()
End Sub
Shared Sub CancelAutoStart()
'取消開機后客戶端自啟動
Dim key, subkey As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser
subkey = key.OpenSubKey("software\microsoft\windows\currentversion\run", True)
subkey.DeleteValue("Client")
subkey.Close()
End Sub
Shared Sub UnLockComputer()
Dim key, subkey As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser
subkey = key.OpenSubKey("software\microsoft\windows\currentversion\policies\system", True)
subkey.SetValue("DisableRegistryTools", 0)
subkey.Close()
'釋放注冊表
subkey = key.OpenSubKey("software\microsoft\windows\currentversion\policies\system", True)
subkey.SetValue("DisableTaskMgr", 0)
subkey.Close()
'釋放任務管理器
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -