Option Explicit
Private Declare Function ShellExecuteA Lib "shell32" (ByVal hwnd As Long, ByVal Op As String, ByVal File As String, ByVal params As String, ByVal directory As String, ByVal ShowCmd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
Y As Long
End Type
Dim selectedPC_index As Integer
Dim ServerList As ListOfServer
Private Sub CmdSearch_Click()
Data1.Recordset.MoveLast
' Declarations
Dim intIDX As Integer
Dim ServerList As ListOfServer
' Set MousePointer to Working Pointer
MousePointer = vbHourglass
' Clear the ListBox
lstComputers.Clear
' Get List of Computers on Network (Type All: Server and Workstation)
ServerList = EnumServer(SRV_TYPE_ALL)
' Loop through all the computers and add them to the listbox
If ServerList.Init Then
For intIDX = 1 To UBound(ServerList.List)
lstComputers.AddItem ServerList.List(intIDX).ServerName
Next
End If
' Restore the MousePointer
MousePointer = vbDefault
End Sub
Private Sub control_Close()
Unload Me
End Sub
Private Sub Command1_Click()
RemoteForm.Show
End Sub
Private Sub Command10_Click()
Dim RemoteHost As String
If lstComputers.Selected(selectedPC_index) = True Then
RemoteHost = lstComputers.List(selectedPC_index)
sckIdentifier.RemoteHost = RemoteHost
sckIdentifier.RemotePort = 8000
sckIdentifier.Connect
Form3.Show
Else
Command10.Enabled = False
End If
End Sub
Private Sub Command6_Click()
Refresh
End Sub
Private Sub Command9_Click()
Dim a
Dim cancel
Beep
a = MsgBox(" Adakah anda pasti untuk keluar dari sini ", vbQuestion + vbYesNo, "Confirm")
If a = vbYes Then
Unload Me
Form4.Show
Else
cancel = True
End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then Unload Me
End Sub
Private Sub Form_Load()
Data1.DatabaseName = App.Path + "\control.mdb"
Dim a As String 'To show out the full name of the login user
a = frmLogin.txtUserid.Text
frmLogin.Data1.Recordset.FindFirst "ID_Pengguna = '" & a & "'"
If frmLogin.Data1.Recordset.NoMatch = False Then
Text15.Text = frmLogin.Data1.Recordset.Fields("Nama_Penuh")
End If
On Error GoTo ConnectError
sckControlPanel.RemoteHost = RemoteForm.sckIdentifier.RemoteHost
sckControlPanel.RemotePort = 8005
sckControlPanel.Connect
Dim x
Dim PCName As String
Dim Command As String
Dim Msg As String
Dim i As Integer
' Declarations
Dim intIDX As Integer
Dim RemoteHost As String
' Clear the ListBox
lstComputers.Clear
' Get List of Computers on Network (Type All: Server and Workstation)
ServerList = EnumServer(SRV_TYPE_ALL)
' Loop through all the computers and add them to the listbox
If ServerList.Init Then
For intIDX = 1 To UBound(ServerList.List)
lstComputers.AddItem ServerList.List(intIDX).ServerName
Next
End If
Text1.Text = "Jumlah Komputer Aktif "
ConnectError:
sckIdentifier.Close
End Sub
Private Sub GetUserBttn_Click()
sckControlPanel.SendData "SystemInfo#"
End Sub
Private Sub lstComputers_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim i As Integer
Dim PCName As String
Dim RemoteHost As String
If lstComputers.Selected(selectedPC_index) = True Then
If Button = 2 Then ' if the mousebutton 2 is pressed (right)
PopupMenu Rclick ' then it calls the menu which is hidden to be shown
' at the cordinates of the mousepointer (x,y)
RemoteHost = lstComputers.List(selectedPC_index)
sckIdentifier.RemoteHost = RemoteHost
sckIdentifier.RemotePort = 8000
sckIdentifier.Connect
Else
If Button = 1 Then
sckIdentifier.Close
Call sckIdentifier_Close
End If
End If
End If
Data1.Refresh
End Sub
Private Sub lstComputers_Click()
'Data1.Recordset.AddNew
selectedPC_index = lstComputers.ListIndex
End Sub
Private Sub mskdata_Click() 'Right clik Masukkan Data
If lstComputers.Selected(selectedPC_index) = True Then
If mskdata.Caption = "Masukkan Data" Then
Form3.Show ' This link to Form 3
ksistem.Visible = True
End If
End If
End Sub
Private Sub ksistem_Click() 'Right Clik Keluar Sistem
If lstComputers.Selected(selectedPC_index) = True Then
Form3.Data1.Recordset.MoveLast
Form3.Data1.Recordset.Edit
Form3.Data1.Recordset.Fields("Masa_Tamat") = " " & Time
Dim a
Dim cancel
Beep
a = MsgBox(" Penggunaan komputer oleh pelajar akan ditamatkan ", vbQuestion + vbYesNo, "Confirm")
If a = vbYes Then
sckIdentifier.Close
Call sckIdentifier_Close
Form3.Data1.UpdateRecord
ksistem.Visible = False
Else
cancel = True
End If
End If
End Sub
Private Sub loff_Click() 'To log off
If lstComputers.Selected(selectedPC_index) = True Then
sckControlPanel.SendData "Logoff#"
End If
End Sub
Private Sub sckControlPanel_Close()
Unload Me
End Sub
Private Sub sckControlPanel_DataArrival(ByVal bytesTotal As Long)
Dim Command As String, txtData As String
Dim Position As Integer
sckControlPanel.GetData txtData
Position = InStr(1, txtData, "#")
Command = Left(txtData, Position - 1)
txtData = Mid(txtData, Position + 1)
Select Case Command
Case "GetUserName"
MsgBox txtData
Case "GetTickCount"
MsgBox Format(txtData, "###")
Case "SystemInfo"
MsgBox txtData
End Select
End Sub
Private Sub sckIdentifier_Close()
If sckIdentifier.State <> sckNotConnected Then
StatusBar1.Panels(1).Text = "Not Connected "
End If
End Sub
Private Sub sckIdentifier_Connect()
Text2.Text = sckIdentifier.RemoteHostIP
StatusBar1.Panels(1).Text = " Connected with '" & sckIdentifier.RemoteHostIP & "' "
Text3.Text = sckIdentifier.RemoteHost
End Sub
Private Sub Text3_Change()
If Form1.Data1.Recordset.NoMatch = True Then
Data1.Recordset.AddNew
Text3.Text = Form1.Data1.Recordset.Fields("N_Komputer")
Text2.Text = Form1.Data1.Recordset.Fields("IP")
Else
End If
End Sub
Private Sub Timer1_Timer() 'To show out the date & time
Text13.Text = " " & Date
Text14.Text = " " & Time
End Sub
Private Sub tutup_Click() 'To shutdown the computer
If lstComputers.Selected(selectedPC_index) = True Then
sckControlPanel.SendData "Shutdown#"
End If
End Sub
Private Sub kunci_Click() 'To lock the computer
If lstComputers.Selected(selectedPC_index) = True Then
sckControlPanel.SendData "LockSystem#"
End If
End Sub
Private Sub restart_Click() 'To restart the computer
If lstComputers.Selected(selectedPC_index) = True Then
sckControlPanel.SendData "Reboot#"
End If
End Sub
Private Sub mkom_Click() 'To get the computer info
If lstComputers.Selected(selectedPC_index) = True Then
sckControlPanel.SendData "GetUserName#"
' Shutdown your particular pc here
'MsgBox ("Your PC named " & lstComputers.List(selectedPC_index) & " is shutdown!")
End If
End Sub
Private Sub MDIForm_Load()
If App.PrevInstance = True Then
Unload Me
Exit Sub
End If
End Sub
This is my coding. Yes i'm using winsock. One name sckControlPanel and another name sckIdentifier. I have been stuck with this for almost 1 week. If u really can help me then i'm really grateful. Thanks alot.