PDA

Click to See Complete Forum and Search --> : Checking if a Computer is on


Jbajin
Jul 11th, 2000, 01:40 PM
I would like to design a program that would check the computers on our network to see if they are on. I usually use a DOS Batch Program to do it. Everything is done by MAC I usually sign in as administrator and the program jumps from each mac and checks the Kernel32.dll file.

It would help to see if I can find out how to move from computer to computer through VB. I also in the process of designing a program to get rid of all our NT profiles and for the program to check out a file for a certain date.

asabi
Jul 11th, 2000, 04:55 PM
well, you can use and ASP page to ping the machines, personally I have never used it before (I just bumped to your post and remembered that i have seen something like that)

http://www.serverobjects.com/products.htm#free

it might help ...

ysa1441
Jul 11th, 2000, 05:27 PM
as u did in dos
u could use a UNC name:
UNC - Universall Naming Convension
in short--
an example: "\\servername\compname\sharename\filename"
or " \\username\sharename\filename"
and then u could check for kernel32.dll like in dos,
a hint:
u can access the computers hidden shared name drive:
"\\usrname\c$"
thats the computers c drive and then u know, so hoped i helped
bye,
yair

Jbajin
Jul 11th, 2000, 05:30 PM
how would I write that in VB? That is probally my problem. I did it in dos. but I don't think it works the same in VB.

Thanks,

Joe

ysa1441
Jul 12th, 2000, 03:33 PM
vb and windows, boths understand this statement:
"\\usrneame\shrname\...."
you can either do like this:

on error goto errhand
open "\\usrname\srhname\...." for input as #1
close #1
errhand:
msgbox("the file doesn't exist")


see this code should make a error if the file doesn't exist, and then it means that the comp is either off, or down, or the file doesn't exist.
anyway this code should do the jos,
bye,
yair

Jul 15th, 2000, 08:21 PM
I like ysa1441's idea of being able to check a file for existence to see if the computer was on, but I think it would be easier to simply to try and connect to the computer (winsock) and see if theres a host not found or similar error.


Private Sub Form_Load()
Winsock1.RemoteHost = ComputerName
Winsock1.RemotePort = Port
End Sub

Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
Set Form = Nothing
Set frmConnectiong = Nothing
End
End Sub

Private Sub Command1_Click()
frmConnecting.Show
frmConnecting.Label1.Caption = "Connecting"
Winsock1.Connect
End Sub

Private Sub Winsock1_Connect()
frmConnecting.Label1.Caption = "Connection Successful"
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

Select Case Number
Case 10061
MsgBox("Error " & Number & " occurred. The remote computer is probably not turned on.", vbRetryCancel + vbCritical, "Error Connecting")
Case 10060
MsgBox("Error " & Number & " occurred. The remote computer stopped responding during sending/receiving.", vbRetryCancel + vbCritical, "Error Connecting")
Case 10056
MsgBox("Error " & Number & " occurred. The remote computer is connected to another computer, try again later.", vbRetryCancel + vbCritical, "Error Connecting")
Case 11001
MsgBox("Error " & Number & " occurred. The specified computer could not be found (the remote computer is probably not turned on), check the computer name in Options.", vbRetryCancel + vbCritical, "Error Connecting")
Case 11002
MsgBox("Error " & Number & " occurred. The specified computer could not be found (the remote computer is probably not turned on), check the computer name in Options.", vbRetryCancel + vbCritical, "Error Connecting")
Case Else
MsgBox("Error " & Number & " occurred when trying to connect to the recipient.", vbRetryCancel + vbCritical, "Error Connecting")
End Select
End Sub


Hope this helps,

Sunny

Jul 16th, 2000, 08:55 PM
The port I use varies, as I am running a flexible software firewall. I usually use 1000, 1001 or 1010, but never:

6667 (IRC)
25 (SMTP)
110 (POP)
21 (FTP)
119 (NNPT)
80 (HTTP)
23 (Telnet)
70 (Gopher)
5000-5011 (Mapped ports)
5000-5012 (Mapped ports)

Sunny

Clunietp
Jul 17th, 2000, 12:19 AM
Those are great ports for servers, but what about workstations on a LAN?

Jul 17th, 2000, 06:26 AM
For communicating in a LAN, I usually use either 1000, 1010 or 1001.

Sunny

Jbajin
Jul 17th, 2000, 11:14 AM
Now if I have a list of MAC address. (that is what we use as the computer name) How do I load them each to the COmputer Name variable to check?

joe

Jul 18th, 2000, 01:32 AM
If the MAC address is the computer name, and want to automatically check all of the computers, I would use a list containing all the addresses, which the VB program wil automatically cycle through connecting to each of them.

just a quick thought:


Option Explicit
Dim ComputerName As Variant

Private Sub Form_Load()
Winsock2.LocalPort = 1000
Winsock2.Listen

List1.AddItem 'namehere
List1.AddItem 'namehere
End Sub

Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
Winsock2.Close
Set Form1 = Nothing
End
End Sub

Private Sub Command1_Click()
Dim x As Integer
For x = 0 To List1.ListCount - 1
ComputerName = List1.List(x)
Winsock1.Close
Winsock1.RemotePort = 1000
Winsock1.RemoteHost = ComputerName
Winsock1.Connect
Wait (1)
Next x
End Sub

Private Sub Winsock1_Connect()
MsgBox "Connection successful to " & ComputerName
Winsock1.Close
End Sub

Private Sub Winsock1_Close()
Winsock1.RemotePort = 1000
Winsock2.LocalPort = 1000
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Could not connect to " & ComputerName
End Sub

Public Sub Wait(seconds)
Timer1.Enabled = True
Me.Timer1.Interval = 1000 * seconds
While Me.Timer1.Interval > 0
DoEvents
Wend
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Timer1.Interval = 0
End Sub


Of course, the program has to be running on both computers :)

Hopes this helps,
Sunny

Jbajin
Jul 20th, 2000, 03:00 PM
Uh.. That seems to be a lot more code that is really necessary. I have to do this to 500 computers and loading this program on each of them is not an option. All I need to do is check for the file using a MAC address as the computer name and then if it doesn't find the file then send that MAC addy to a List box that is is.

Jul 21st, 2000, 01:25 AM
if running a program on all the computers is not an option for you, then the best thing to do would be to try and open a file on a remote computer and monitor the error message (of any) as ysa1441 has demostrated.

But you must make sure that the file you check for must exsist, eg C:\Command.com on Win9x machines (I think). Another problem is the need for the file you check to be on the same drive name on every computer (eg, all are c:)

Another problem is the time it takes to detect that the file doesn't exist. It may take several seconds for the computer to realise the remote computer is not responding, so for 500 computers it may take some time..

And of course....you should add some code that saves the computer names on your list1, so you don't have to type it all up everytime! :)


Option Explicit

Private Sub Command1_Click()
Dim x As Integer

For x = 0 To List1.ListCount
On Error GoTo erhandler
Open "\\" & List1.List(x) & "\c\command.com" For Input As #1
Close #1
Next x

erhandler:
List2.AddItem List1.List(x)
End Sub



Sunny