Sign in to follow this  
Followers 0
Jkeith247

A more efficient way of monitoring pc's?

4 posts in this topic

#1 ·  Posted (edited)

Hello all!

I am working on an app that will monitor the status of 16 pc's on a network. Pinging them works great, the only problem is, while the program is pinging, it does not accept any other forms of input. This essentially locks up the program until the pinging is done. Is there a more efficient way of doing this?

Thanks!!

While 1
    ;Following conditional statement monitors pc1
    $var1 = Ping($ip1,50)
If $var1 Then
    GUICtrlCreateLabel("PC 1 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 1 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
    ;Following conditional statement monitors pc2
    $var2 = Ping($ip2,50)
If $var2 Then
    GUICtrlCreateLabel("PC 2 is ONLINE  ", 170, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 2 IS OFFLINE", 170, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc3
    $var3 = Ping($ip3,50)
If $var3 Then
    GUICtrlCreateLabel("PC 3 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 3 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc4
    $var4 = Ping($ip4,50)
If $var4 Then
    GUICtrlCreateLabel("PC 4 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 4 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc5
    $var5 = Ping($ip5,50)
If $var5 Then
    GUICtrlCreateLabel("PC 5 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 5 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc6
    $var6 = Ping($ip6,50)
If $var6 Then
    GUICtrlCreateLabel("PC 6 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 6 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc7
    $var7 = Ping($ip7,50)
If $var7 Then
    GUICtrlCreateLabel("PC 7 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 7 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc8
    $var8 = Ping($ip8,50)
If $var8 Then
    GUICtrlCreateLabel("PC 8 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 8 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc9
    $var9 = Ping($ip9,50)
If $var9 Then
    GUICtrlCreateLabel("PC 9 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 9 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc10
    $var10 = Ping($ip10,50)
If $var10 Then
    GUICtrlCreateLabel("PC 10 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 10 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc11
    $var11 = Ping($ip11,50)
If $var11 Then
    GUICtrlCreateLabel("PC 11 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 11 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc12
    $var12 = Ping($ip12,50)
If $var12 Then
    GUICtrlCreateLabel("PC 12 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 12 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc13
    $var13 = Ping($ip13,50)
If $var13 Then
    GUICtrlCreateLabel("PC 13 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 13 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc14
    $var14 = Ping($ip14,50)
If $var14 Then
    GUICtrlCreateLabel("PC 14 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 14 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc15
    $var15 = Ping($ip15,50)
If $var15 Then
    GUICtrlCreateLabel("PC 15 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 15 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
;Following conditional statement monitors pc16
    $var16 = Ping($ip16,50)
If $var16 Then
    GUICtrlCreateLabel("PC 16 is ONLINE  ", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0x00ff00)
Else
    GUICtrlCreateLabel("PC 16 IS OFFLINE", 60, 110, 85, 15, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xff0000)
EndIf
Sleep (30000)
Wend
Edited by Jkeith247

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have two functions (pinging the PCs on one side and the GUI with additional functions on the other side) which you now try to handle with a single script.

I would split it into two scripts running concurrently. One script is running in the background and pings the PCs in a loop. The result is stored in the registry / an ini file / whatever.

The second script does the GUI plus the additional stuff. When the user wants to know if the PCs are up and running, read the data and display the result.

If the GUI script is closed set a key in the registry / and entry in the ini file ... to let the first script know that it has to exit as well.

Just my 2 cts.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I thought about that, that is a great idea, Thank you!

Do you think it would be better to do this through the registry or an ini file? Which is faster? One would assume the registry, but I could be wrong...

Thanks again!

Share this post


Link to post
Share on other sites

Don't know.

If there is a difference it will be quite small.

It depends on how often you will do a ping and if you write the results after each ping. If you expect the 16 PCs to be up most of the time I would suggest to ping all 16 PCs, store the results in an array and then write the array at once. Wait a minute and then start over again.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0