Jump to content

Is VNC running on remote PC?


Recommended Posts

Dear All,

I have just discovered the wonderful world of AutoIT. I am trying to create an application for our school where we use WinVNC for screencasting content on teacher's PC onto the students' PCs. We use WinVNC viewer. We start VNCViewer on all clients in listening mode and then I will connect from the VNC server to each of the client PCs.

I have managed to create a simple script that reads the workstation names from a text file, I convert the viewer PC names to their respective IPs and connect to the listening PCs. My problem lies in checking whether the VNCViewer is running on a 'student' PC before connecting to it. I have started the TCP services, used TCPConnect on the VNCViewer port and works as a test before connecting to the remote PC. Problem lies with 'student' PCs either switched off or with VNC Viewer not started as when TCPConnect tries to connect and fails and waits for about 25 seconds before timing out. There is a TCPTimeout option I tried but does not seem related.

Can anyone help in solving this problem, i.e. trying to connect to a remote TCP port and if no response is received, do not wait and return immediately?

Your help would be greatly appreciated! :P

Link to comment
Share on other sites

Here's an idea, I use it with SMS all the time but have not tried it for something like this, why not use (SysInternals) PSList.exe to scan the remote computer processes as a check to confirm if VNC is running.....put it in a loop and look for the WinVNC process, if you get a fail, use PSExec.exe to start it up then create message boxes on fail or success for each computer you have listed as not running. I don't think it would be that hard to do IMHO. (This assumes firewall is off and remote registry is running on XP)

Edited by Legacy99
Link to comment
Share on other sites

Wow that's a great idea! Had not thought of that as an option. Will try it out thanks!

But just a sec that relies on another app. Is it possible to make it completely self contained and try talk to the VNC port on 5500 remotely.... When this is running I get a response (as it is always on at startup), but if remote PC is off, faulty or VNC viewer is not switched on, TCPConnect on port 5500 waits for 25 seconds....

My current AutoIt script works fine in the loop connects to the remote PC, but when one of the PCs is off....stops execution for 25 seconds....

Any clues?

Link to comment
Share on other sites

...I have just discovered the wonderful world of AutoIT...

Welcome to the forum.

I'm going to do something that I rarely do; I'm going to suggest that you change the way that the connections are made. You probably have good reasons for using VNC the way that you are - so this suggestion might be a waste of our time:

===============

Have one shortcut on the teacher's desktop to start the normal VNC service.

[...winvnc4.exe" -noconsole -start]

Have a second one to stop that same service.

[...\winvnc4.exe" -noconsole -stop]

Setup the teacher's VNC server to:

"Always treat new connections as shared."

[Let me know if you need help doing this. *]

On each client, place a shortcut to connect to the teacher's system. That shortcut should point to a VNC config file that is on a protected server. Within that config file, you can set it to make a "view only" connection.

[Let me know if you need help doing this. *]

* There is little reason to elaborate if this connectivity model is not workable for the teacher/students.

===============

One usage model for that type of connectivity is:

The teacher starts the service

Tells the students to connect by double clicking on the shortcut

When finished, the teacher stops the service

[all of the clients are automatically disconnected]

If the students can be trusted - the teacher may be able to get by with leaving the VNC service running at all times. The teacher can still automatically disconnect all clients if desired.

Hope this helps...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

...But just a sec that relies on another app. Is it possible to make it completely self contained and try talk to the VNC port on 5500 remotely....

If you don't use the connectivity model that I suggested above, then you can stick with your current method/script and have one main script that starts a child script for each client/student system. This can be done a few clients at a time or all at once depending on the number of clients and the hardware of the teacher's system.

The child script would make make the connection or an error window. The child script would be started with a command line that passes the IP or computer name of interest.

Edit: Forgot to list the reason for doing it this way - in case it is not obvious. Any 25 second waits would be in parallel instead of serial like in your current loop.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Yes PING is what I use currently but it is no guarantee that the VNC viewer on all client PCs have been started, and besides that have to enable ICMP echo on each of the workstations.

I have to use the said model so that the teacher has control over starting and terminating the sharing session and not leaving it to the students to "listen" to teacher explanation. What I am currently using is the following:

;Check workstations in file

For $nLoop = 1 to $aWorkstations[0]

;Convert PC Name to IP Address

$sIP = TCPNameToIP($aWorkstations[$nLoop])

;Ping machine and await response

$nWSPing = Ping($sIP, 50)

;If response is received connect workstation

If $nWSPing = 1 then

ShellExecuteWait($ServerProcessName, "-connect " & $sIP, $ServerProcessPath, "open", @SW_HIDE)

Else

Beep(500, 50)

EndIf

Next

This loop tries to ping the workstation, and if it obtains a response executes with ShellExecuteWait to connect a client to the running server, if not script beeps. Can I just use TCPconnect and check if port 5500 is running and if so connect.

How can I prevent the loop from stopping execution and waiting for a student PC that is not switched on or does not have WinVNC listener running?...Ok just a moment what is best for me to use ShellExecuteWait, ShellExecute, Run, RunWait?.....

Thanks all for your precious help, on such an active forum!! :P

Link to comment
Share on other sites

Yes your right it's relying on external apps but you could use the fileinstall function to "embed" the apps in your script so it's self contained. If it was me (but it's not) that would be the way I would do it (sure it's not pure Autoit but why re-invent the wheel).

Use the apps right off the bat to test the pc's before you make the VNC connection, that way your ensuring the pc's are online and running VNC, then continue with your connections, your avoiding your 25 second delay that way. Also, as I think of it, in your script you could add in a Wake on Lan Function for computers that are turned off too. WakeOnLan Script

Link to comment
Share on other sites

Many thanks Legacy. Pls bear with my being a newbie with AutoIt. Is there some function which does the following then.

Test TCP port 5500 on defined IP address, if successful ok connect to it otherwise, if no response (say within a custom timeout like 50ms) then do not connect?

Link to comment
Share on other sites

are you trying something like (Keep in mind this is crude)

$g_IP = "192.168.1.101"
$port = 5500
$nWSPing = Ping($g_IP,400)

If $nWSPing <> 1 then
   Msgbox(0,"", "Ping Failed for " & $g_IP & "  " & $nWSPing)
   Exit
Else
    Msgbox(0,"", "Ping Succeded for " & $g_IP)
   ; Start The TCP Services
   TCPStartUp()

  ; Connect to a Listening "SOCKET"
  $socket = TCPConnect( $g_IP,  $port )
    If $socket = -1 Then 
      Msgbox(0,"VNC not running", $g_IP & " is not listing on port " & $port)
      Exit
  Else
      Msgbox(0,"VNC is running", $g_IP & " is listing on port " & $port)
    Endif

Endif

...on with script
Link to comment
Share on other sites

are you trying something like (Keep in mind this is crude)...

Pardon me for sticking my nose in again.

If ping proves that the computer is running

- then this code where you check that vnc is running:

; Connect to a Listening "SOCKET"

$socket = TCPConnect( $g_IP, $port )

...will take 25 seconds to return an answer if VNC is not loaded.

This is what bengrech was attempting to avoid in the first place... or what bengrech wants to change to return an answer within 50ms

Let's say that bengrech is looping thru 30 clients and the first 12 return a good ping, but are not running VNC. See the problem? He waits 12 times 25 seconds before the script makes the first good VNC connection.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Yes herewasplato has understood my problem 101%

Legacy's solution is better than mine as it will check VNC before attempting to connect but there is no derived advantange in what I seek to solve because I will be stuck just the same with 25 second waits for each "student" PC not running the VNC listener.

On another note another member has recommended ShellExecute as against ShellExecuteWait. Will using the Exec only version connect, and if one workstation does not have VNC listener running keep a "thread" waiting for 25 seconds...Coz this would help too....even though not best of the best of solutions?

Link to comment
Share on other sites

@bengrech,

Just for fun - what is wrong with the method mentioned in this post?

http://www.autoitscript.com/forum/index.ph...st&p=560770

Since you are new to AutoIt, I should have made myself clearer in this post:

http://www.autoitscript.com/forum/index.ph...st&p=560773

...I tested the concept by having the main script start 200 copies of a second (child) script. Each child script does what you want done for one client:

ping to see if it is alive - if not, make an error msg

TCP to the VNC port - if no answer, make error msg

connect server to client <<< I skipped this during my testing

Keep in mind that all 200 "children" are running in parallel, so you will get a connection or an error msg for all 200 clients within a minute or two.

I doubt that you have 200 clients to connect, but when I test something - I like to see where the limits are. All 200+ scripts ran fine on a laptop with only 512MB of RAM. Sure, the swap file was working hard, but nothing crashed and I tested it more than once.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

There is absolutely nothing wrong with the first recommended method, as per following post

http://www.autoitscript.com/forum/index.ph...st&p=560770

but this method it is at the descretion of the students to connect, which is not always desirable.

Ok will try the second method as recommended. Would it be as so:

Create a child script executable that pings, checks vnc port and connects.

The main script should run the child script using what ShellExecute, ShellExecuteWait, Run or RunWait? What would you recommend?

Link to comment
Share on other sites

$address = "127.0.0.1"
$result = VNC_Check()
MsgBox(0,$address,$result)

Func VNC_Check($strComputer = "localhost")

    Local $colItems = ""
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE name = 'winvnc'", "WQL", 0x10 + 0x20)

    If IsObj($colItems) Then
        For $objItem In $colItems
            If $objItem.Started <> 0 Then Return True
        Next
        Return False
    Else
        Return SetError(1,0,False)
    EndIf
    
    Return False
EndFunc   ;==>VNC_Check

Link to comment
Share on other sites

...it is at the descretion of the students to connect, which is not always desirable.

Agreed. I had hoped that we were dealing with adults who had paid money for the class :-) and might be a bit more compliant.

The main script should run the child script using what ShellExecute, ShellExecuteWait, Run or RunWait? What would you recommend?

Run

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • 3 years later...

Hi Guys

I am trying to do a similar script but i am looking for connecting to remote pcs and looking for a specific port running

#include <File.au3>

#include <Array.au3>

Global $HostFile =

$g_IP = ""

$port =

$nWSPing = Ping($g_IP,400)

If $nWSPing <> 1 then

Msgbox(0,"", "Ping Failed for " & $g_IP & " " & $nWSPing)

Exit

Else

Msgbox(0,"", "Ping Succeded for " & $g_IP)

; Start The TCP Services

TCPStartUp()

; Connect to a Listening "SOCKET"

$socket = TCPConnect( $g_IP, $port )

If $socket = -1 Then

Msgbox(0,"LunaticVoice not running", $g_IP & " is not listing on port " & $port)

Exit

Else

Msgbox(0,"LunaticVoice is running", $g_IP & " is listing on port " & $port)

Endif

Endif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...