Jump to content

Ping utility GUI


Recommended Posts

Hello, I am new to the forums as a poster, I have utilized code from here before and it has always been great. So I have a question, I got this code form this forum and it works great. I want to make a GUI instead of the text file for results and make it ping in a loop until I stop it. Any ideas or other posts you can point me to would be great. Thank you again for all of the time you spend helping us less intelligent.

Scott

Option Explicit Const ForReading = 1, ForWrite = 2, ForAppend = 8' Oblects And Varibles Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\cimv2") Dim i, Obj, strText, Results1,Results2, Ts'-> Check For Servers.txt  If Fso.FileExists(Fso.GetParentFolderName(WScript.ScriptFullName) & "\servers.txt") Then'-> Process The Text File With The Server Information   Set Ts = Fso.OpenTextFile("servers.txt", ForReading)	strText = Ts.ReadAll	Ts.Close'-> Loop One Process The Servers.txt	 For Each i In Split(strText, vbCrLf)'-> Loop To Ping Each Server From Servers Text	  For Each Obj in Wmi.ExecQuery("Select * From Win32_PingStatus where Address = '" & i & "'")	   If IsNull(Obj.StatusCode) Or Obj.StatusCode <> 0 Then 		 Results2 = Results2 & " Computer Off Line : "  & i & vbCrLf	   Else		 Results1 = Results1 & " Computer On Line  : " &  i & vbCrLf 	   End If	 Next   	Next '-> Create The Results Text File	Set Ts = Fso.CreateTextFile("results.txt")	Ts.WriteLine "Ping From Server.txt Results" & vbCrLf & " Date And Time	 : " & Now & Vbcrlf	Ts.WriteLine Results1	Ts.WriteLine Results2	Ts.Close()	Act.Run("notepad.exe " & Chr(34) & "results.txt" & Chr(34)),1,True   Else	MsgBox vbTab & "Error" & vbcrlf &_	"Missing, the server.txt to process. You" & vbCrLf & _	"must create a servers.txt with an IP or" & vbCrLf & _	"Computer Name, with one per line",4128,"Error"   End If
Link to comment
Share on other sites


If you can use Powershell, this submission from last year may provide inspiration.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  $Form = New-Object System.Windows.Forms.Form    $Form.Size = New-Object System.Drawing.Size(600,400)  $Form.StartPosition = "CenterScreen" #loads the window in the center of the screen$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedToolWindow #modifies the window border$Form.Text = "Ping GUI tool" #window description############################################## Start functionsfunction procInfo {$computer=$DropDownBox.SelectedItem.ToString() #populate the var with the value you selected$pingResult=ping $computer | fl | out-string;$outputBox.text=$pingResult                     } #end procInfo############################################## end functions############################################## Start drop down boxes$DropDownBox = New-Object System.Windows.Forms.ComboBox$DropDownBox.Location = New-Object System.Drawing.Size(20,50) $DropDownBox.Size = New-Object System.Drawing.Size(180,20) $DropDownBox.DropDownHeight = 200 $Form.Controls.Add($DropDownBox) $wksList= Get-Content .\servers.txtforeach ($wks in $wksList) {                      $DropDownBox.Items.Add($wks)                              } #end foreach############################################## end drop down boxes############################################## Start text fields$outputBox = New-Object System.Windows.Forms.TextBox $outputBox.Location = New-Object System.Drawing.Size(10,150) $outputBox.Size = New-Object System.Drawing.Size(565,200) $outputBox.MultiLine = $True $outputBox.ScrollBars = "Vertical" $outputBox.Font = New-Object System.Drawing.Font("Verdana",8,[System.Drawing.FontStyle]::Italic)$Form.Controls.Add($outputBox) ############################################## end text fields############################################## Start buttons$Button = New-Object System.Windows.Forms.Button $Button.Location = New-Object System.Drawing.Size(400,30) $Button.Size = New-Object System.Drawing.Size(110,80) $Button.Text = "Ping" $Button.Add_Click({procInfo}) $Button.Cursor = [System.Windows.Forms.Cursors]::Hand$Button.BackColor = [System.Drawing.Color]::LightGreen$Button.Font = New-Object System.Drawing.Font("Verdana",14,[System.Drawing.FontStyle]::Bold)$Form.Controls.Add($Button) ############################################## end buttons$Form.Add_Shown({$Form.Activate()})[void] $Form.ShowDialog()
The above is taken directly from episodes one and two of the fore-mentioned submission with the only change being the array which is populated from your local file, servers.txt.
Link to comment
Share on other sites

Yzowl,

Thanks I will look at Powershell and the other post. Thanks!

gunsmokingman,

I have been messing with HTA and I like the way it works. So I may lean in that direction, any help would be great.

Scott

Link to comment
Share on other sites

This is a HTA that demo how to use a function like a loop, it has some basic controls that stop, re start, re set, close.

<!-- Hta And Script By Gunsmokingman Aka Jake1Eye This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use. This is only posted as example code and meant only to used as such.--><TITLE>Demo Timer</TITLE> <HTA:APPLICATION ID="Demo Timer"    SCROLL="No"		      SCROLLFLAT ="No"     SingleInstance="Yes"      ShowInTaskbar="No"		      SysMenu="No"		     MaximizeButton="No"		   MinimizeButton="No"	   Border="Thin"    BORDERSTYLE ="complex"    INNERBORDER ="No"     Caption="Yes"		     WindowState="Normal"    APPLICATIONNAME="DTimer"   Icon="%SystemRoot%\explorer.exe"><STYLE type="text/css">  Body   {    Padding-Top:1pt;Padding-Bottom:1pt;Margin:1pt;    Font-Size:10.25pt;Font-Weight:Bold;    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;    Color:Black;BackGround-Color:#EFE9E3;    Text-Align:Center;Vertical-Align:Top;   }  DIV   {    Font-Size:10.25pt;Font-Weight:Bold;Color:#00A1A1;    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;   }  TD   {    Font-Size:10.25pt;Font-Weight:Bold;Color:#515151;    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;   }  BUTTON   { 	  Height:15pt;width:51pt;Cursor:Hand;	  Font:8.25pt;Font-weight:bold;	  Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;	  Color:#404040;Text-Align:Center;Vertical-Align:Middle;	  filter:progid:DXImageTransform.Microsoft.Gradient	  (StartColorStr='#E5E5E5',EndColorStr='#7D7D7D');	  Margin:1;Padding:2;	  Border-Left: 1px Transparent;Border-Right: 2px Transparent;	  Border-Top: 1px Transparent;Border-Bottom: 2px Transparent;   }</STYLE><SCRIPT LANGUAGE='VBScript'>'-> Resize And Place In Approx Center Of Screen Dim Wth, Hht :Wth = int(327) :Hht = int(150)  window.ResizeTo Wth, Hht  MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2)) Dim C1, H1, M1, T1, Tm1, txt  Function Window_OnLoad()  C1=0 :H1=0 :M1=0  Counter()  End Function '-> To Keeps The Script In An Infinte Loop Until User Interaction  Function Counter()'-> Reset The Seconds And Minutes Every 60 Cycles   If C1 = 60 Then :M1 = M1 + 1 :C1 = 0   If M1 = 60 Then :H1 = H1 + 1 :M1 = 0'-> To Display 02 Digits Ex 1 = 01   If Len(C1) = 1 Then C1 = "0" & C1   If Len(M1) = 1 Then M1 = "0" & M1   If Len(H1) = 1 Then H1 = "0" & H1   T1 = Split(Time(),":")   If Len(T1(0)) = 1 Then T1(0) = "0" & T1(0)   If Len(T1(1)) = 1 Then T1(1) = "0" & T1(1)    Tx1.style.color="#9A0000" :Tx1.innerHTML=H1     Tx2.style.color="#009a00" :Tx2.innerHTML=M1     Tx3.style.color="#00009a" :Tx3.innerHTML=C1     Dim S :S = Split(T1(2), " ")     If Len(S(0)) = 1 Then S(0) = "0" & S(0)    Tx4.style.color="#009595"    Tx4.innerHTML=T1(0) & ":" & T1(1) & ":" & S(0)  & " " & S(1)   C1 = C1 + 1   Tm1=window.setTimeout("Counter()",1000,"VBScript")   End Function</SCRIPT><BODY Scroll='No'><TABLE>Demo Timer</TABLE> <TABLE>    <TD><TD>Hours »</TD><TD><DIV ID='Tx1'>00 </DIV></TD></TD>  <TD><TD>Minutes »</TD><TD><DIV ID='Tx2'>00</DIV></TD></TD>  <TD><TD>Seconds »</TD><TD><DIV ID='Tx3'>00</DIV></TD></TD> </TABLE> <TABLE> <BUTTON ID='Bn1' OnClick="window.clearTimeout(Tm1)">Stop</BUTTON> <BUTTON ID='Bn2' OnClick="Counter()">Re-Start</BUTTON> <BUTTON ID='Bn3' OnClick="window.clearTimeout(Tm1): Window_OnLoad()">Re-Set</BUTTON> <BUTTON ID='Bn4' OnClick="window.clearTimeout(Tm1): window.close()">Close</BUTTON> </TABLE> <TABLE>  <TD><DIV ID='Tx4'>00:00 PM</DIV></TD> </TABLE></BODY>
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
  • Recently Browsing   0 members

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