KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

My NETWORK TRAFFIC LIGHTS

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Fri May 04, 2007 12:59 pm    Post subject: My NETWORK TRAFFIC LIGHTS Reply with quote

Very Happy
I have been after a tool to monitor the PC's on my Network, Who is using them etc, interactivly.
With the advent of .net I find I have sufficient programming resources for the job.
I am however as an infrequent scripter struggling with a couple of areas on which I hope you can give some constructive advice.
This is the bare bones code which runs as two processes by necessity.
(I have not as yet got to grips with how listboxes are indexed so currently have an array with the same information. I would like in future to reduce this overhead.)

I am struggling with the CASE statements for the radio buttons which never selects what is desired = ExecTask()

I also wanted to check whether the list view text is displayed as 'red' or 'green' (HENCE TRAFFIC LIGHTS) so I would only act upon 'Green' items, and ignore 'Red' ones. I have ; out some of my offending code.

Some Minor notes;
The wmi ping tends to see the pinging machine as not there..assume a timing issue ?
Listbox has only one column of data but auto defaults to horizontal scroll bar rather than vertical.

Code:

;Network TRAFFIC LIGHTS (MACE(C)2007) Section 1 of 2 = NTL.kix
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
Global $INIFILE, $WsName[999,1]
$INIFILE="%temp%\PingDomC.ini"
$Script=split(@SCRIPTNAME,".")
$CMD = @SCRIPTEXE+" "+@scriptdir+"\"+$script[0]+"#2.kix"
If not Exist($INIFILE)
  run $CMD
Endif
;$SCREENWIDTH=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)
;$SCREENHEIGHT=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)
$SCRNW=130
$SCRNH=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)-10
$Form = $System.Form()
;$Form.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form.Top=5 ;Position of TOP LEFT from TOP
$Form.Left=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)-140 ;Position of TOP LEFT from SCREEN LEFT
$Form.Size = $System.Size($SCRNW,$SCRNH) ;(Width,Height)
$Form.Text = @Domain
$Form.maximizebox = "false"
$Form.minimizebox = "false"
$Form.ShowInTaskBar = "False"

$ListView = $System.ListView()
$ListView.Height = $SCRNH-170
$ListView.Left = 0
$ListView.KeyDown = "KeyDownEvent()"
$ListView.KeyPress = "SelectItemEvent()"
$ListView.Click = "OnClick()"
$ListView.MultiSelect = 0  ;False
$ListView.Sorting = 1  ;Ascending
$ListView.Top = 0
$ListView.Width = $SCRNW
$ListView.View = $System.View_List
$ListView.AutoArrange = "True"
;$ListView.Items.Item(0).Selected = -1 ;True
$nul = $Form.Controls.Add($ListView)
$Form.AcceptButton = $OnClick

$oDomain = GetObject("WinNT://@LDomain")
$filter = "Computer",""
$oDomain.filter = $filter

$TextBox = $System.TextBox()
$TextBox.Left = 0
$TextBox.Top = $SCRNH-166
$TextBox.Width = $SCRNW - 35
$nul = $Form.Controls.Add($TextBox)

$OKEnter = $System.Button()
$OKEnter.Click = "OK_Enter()"
$OKEnter.Name = "OKEnter"
$OKEnter.Text = "OK"
$OKEnter.Width = 30
$OKEnter.Left = $SCRNW-34
$OKEnter.Top = $SCRNH-166
$nul = $Form.Controls.Add($OKEnter)
$Form.AcceptButton = $OKEnter

$RadioBtn0 = $System.radiobutton()
$RadioBtn0.Left = 7
$RadioBtn0.Text = "WHO is this"
$RadioBtn0.Top = $SCRNH-148
$RadioBtn0.Width = $SCRNW
$RadioBtn0.checked = "True"
$nul = $Form.Controls.Add($RadioBtn0)

$RadioBtn1 = $System.radiobutton()
$RadioBtn1.Left = 7
$RadioBtn1.Text = "Explore Drive C$"
$RadioBtn1.Top = $SCRNH-130
$RadioBtn1.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn1)

$RadioBtn2 = $System.radiobutton()
$RadioBtn2.Left = 7
$RadioBtn2.Text = "RDP to Computer"
$RadioBtn2.Top = $SCRNH-112
$RadioBtn2.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn2)

$RadioBtn3 = $System.radiobutton()
$RadioBtn3.Left = 7
$RadioBtn3.Text = "VNC to Computer"
$RadioBtn3.Top = $SCRNH-94
$RadioBtn3.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn3)

$RadioBtn4 = $System.radiobutton()
$RadioBtn4.Left = 7
$RadioBtn4.Text = "Restart Computer"
$RadioBtn4.Top = $SCRNH-76
$RadioBtn4.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn4)

$RadioBtn5 = $System.radiobutton()
$RadioBtn5.Left = 7
$RadioBtn5.Text = "Shutdown Computer"
$RadioBtn5.Top = $SCRNH-58
$RadioBtn5.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn5)

$Timer = $System.Timer
$Timer.Interval = 3000 ; msecs
$Timer.Tick = "PingRead"
$Timer.Start
sleep 2

$Form.Show  ;Displays the Form
While $Form.Visible
   $Nul = Execute($Form.DoEvents())
Loop
del $INIFILE /c /f
Quit()

Function KeyDownEvent()
   $KeyCode = $ListView.KeyDownEventArgs.KeyCode
    If $KeyCode = 37 Or $KeyCode = 38 Or $KeyCode = 39 Or $KeyCode = 40
         $TextBox.Text = $ListView.FocusedItem.Text
   EndIf
   $Form.Activate
EndFunction

Function onclick()
   ;If $ListView.FocusedItem.ForeColor = $System.Color.FromName('Green')
         $TextBox.Text = $ListView.FocusedItem.Text
   ;EndIf
   $Form.Activate
EndFunction

Function SelectItemEvent()
  $TextBox.Text = $ListView.FocusedItem.Text
   If $ListView.KeyPressEventArgs.KeyChar = chr(13)
   $nul = ExecTask($TextBox.Text)
   Endif
  $Form.Activate
EndFunction

Function OK_Enter()
  $TextBox.Text = $ListView.FocusedItem.Text
   $nul = ExecTask($TextBox.Text)
  $Form.Activate
EndFunction

Function ExecTask($Computer)
; If $ListView.FocusedItem.ForeColor = $System.Color.FromName('Red')
;  $nul= MessageBox("This Unit is currently considered inactive"+chr(10)+chr(10)+"Please select an active Unit.",$NWCompName,16)
; ELSE
   SELECT
    Case $RadioBtn0.checked = "True"
    $Nul = WHOIS($Computer)
    Case $RadioBtn1.checked = "True"
    $Nul = Explore($Computer)
    Case $RadioBtn2.checked = "True"
    $Nul = RDP($Computer)
    Case $RadioBtn3.checked = "True"
    $Nul = VNC($Computer)
    Case $RadioBtn4.checked = "True"
    $Nul = RESTART($Computer)
    Case $RadioBtn5.checked = "True"
    $Nul = SHUTDOWN($Computer)
   EndSelect
;endIf
$Form.Activate
EndFunction

Function PingRead();Read in on timer current status of machines.
 $ListView.BeginUpdate
 Dim $ecount, $Count, $a, $Count, $ADD
 If $Ecount < 100  ; If failed to open file # times - exit.
  If Open (8,$INIFILE,2) = 0
   $Count = 0
   $a = readline(8)
   WHILE NOT @error
    $Count = $Count + 1
    if $WsName[$count,0] = ""
     $ADD=1
    Endif
    $linearray = Split($a, ",")
    $x=0
    For each $element in $Linearray
    $WsName[$Count,$x] = $element
    $x=$x+1
    next
    IF $ADD = 1
     $ = execute("$$Item$Count = $$ListView.Items.Add($$System.ListViewItem($$WsName[$$Count,0]))")
    Endif
    if $WsName[$count,1] = "1"
      $ = execute("$$Item$Count.ForeColor = $$System.Color.FromName('Green')")
    Else
      $ = execute("$$Item$Count.ForeColor = $$System.Color.FromName('Red')")
    Endif
   $a = readline(8)
   LOOP
   $ = Close(8)
  Else
   $ecount=$ecount+1
  Endif
  $Total=$Count - 1
 Else
    Messagebox("Unable to open "+$INIFILE+". TERMINATING !","ERROR",16)
    del $INIFILE /c /f
    Quit()
 Endif
 $ListView.EndUpdate
EndFunction

FUNCTION WHOIS($NWCompName)
  $Query = "Select * from Win32_ComputerSystem"
  $oWMI = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $NWCompName + "\root\cimv2")
  $cItems = $oWMI.ExecQuery($Query)
  For Each $oItem In $cItems
   If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
    $nul= MessageBox("NO ONE IS"+chr(10)+"LOGGED ON",$NWCompName,64)
    exit 1
   Else
    $nul= MessageBox(ucase($oItem.UserName),"User on:"+$NWCompName,64)
   EndIf
  Next
ENDFUNCTION

FUNCTION RDP($NWCompName)
  $cmd = "mstsc.exe /v:"+$NWCompName+":3389 /F"
  RUN $cmd
ENDFUNCTION

FUNCTION VNC($NWCompName)
  $nul= MessageBox("Connect using VNC",$NWCompName,289,30)
;  $cmd = ""
;  RUN $CMD
ENDFUNCTION

FUNCTION RESTART($NWCompName)
  $MSG='"Emergency CANCEL ='+chr(10)+'Start + Run then Type'+chr(10)+'SHUTDOWN -A"'
  $cmd = 'SHUTDOWN -r -f -T 30 -m \\'+$NWCompName+' -c '+$MSG
  set "SD=$CMD"
  if (MessageBox("This will 'DUMP & KILL' any"+chr(10)+"current session and will"+chr(10)+"lose all associated data.","RESTART '"+$NWCompName+"'",305,30)) = 1
   RUN $cmd
  Endif
ENDFUNCTION

FUNCTION SHUTDOWN($NWCompName)
  $cmd = 'SHUTDOWN -s -f -T 30 -m \\'+$NWCompName+' -c '+$MSG
  if (MessageBox("This will 'DUMP & KILL' any"+chr(10)+"current session and will"+chr(10)+"lose all associated data.","SHUTDOWN '"+$NWCompName+"'",305,30)) = 1
   RUN $cmd
  Endif
ENDFUNCTION

FUNCTION EXPLORE($NWCompName)
  $cmd = 'explorer.exe "\\'+$NWCompName+'\C$"'
  if (MessageBox("This will open the"+chr(10)+"management C$ share"+chr(10)+"on this UNIT !","EXPLORE '"+$NWCompName+"'",305,30)) = 1
   RUN $cmd
  Endif
ENDFUNCTION


Code:

;Network TRAFFIC LIGHTS (MACE(C)2007) PING SECTION 2 of 2 = NTL#2.kix
Break On
Global $Total, $Count, $INIFILE
Global $WsName[999,1]
$INIFILE="%temp%\PingDomC.ini"
$ = ListADcomp
$ = writeINI
while exist($INIFILE)
 $=PingAll
Loop
del $INIFILE /c /f
Quit()

Function ListADComp()
$oDomain = GetObject("WinNT://@LDomain")
$filter = "computer",""
$oDomain.filter = $filter
$Count=1
For Each $oWs In $oDomain
 $WsName[$Count,0] = $oWs.Name
 $WsName[$Count,1] = "0"
 $Count=$count+1
Next
$Total = $Count - 1
EndFunction


Function PingAll()
     Dim $Query,$oWMI,$oItem,$cItems,$wmiPing
     if $Count < 1 or $Count > $Total
      $Count = 1
     Endif
     $Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $WsName[$count,0] + "'"
     $oWMI = GetObject("winmgmts:root\cimv2")
     $cItems = $oWMI.ExecQuery($Query)
     For Each $oItem In $cItems
      If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
         $Active = "0"
      Else
         $Active = "1"
      EndIf
     Next
     If $WsName[$count,1] <> $Active
         $WsName[$count,1] = $Active
         $ = WriteINI
     Endif
     $Count=$Count+1
EndFunction

Function WriteINI()
Dim $ecount, $line
Del $INIFILE /c /f
while not exist($INIFILE) and $ecount < 5
 If Open (7,$INIFILE,5) = 0
  For $line = 1 to $TOTAL
   $ = WRITELINE (7,$WsName[$line,0]+","+$WsName[$line,1] + @crlf)
  next
 Else
  $ecount = $ecount+1
 EndIF
 $ = Close(7)
Loop
if $ecount >= 5
 Messagebox("Unable to create "+$INIFILE+". TERMINATING !","ERROR",16)
 Quit()
Endif
EndFunction

________
Motorcycle tires


Last edited by MACE1 on Fri Feb 18, 2011 5:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Fri May 04, 2007 2:41 pm    Post subject: Reply with quote

Have you checked the value that is getting returned?

? $RadioBtn0.Checked

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri May 04, 2007 4:19 pm    Post subject: Reply with quote

I am tring to test your code but can't find were you define $Computer
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri May 04, 2007 4:29 pm    Post subject: Reply with quote

ok, i have defined $Computer as @WKSTA inside the 'ExecTask()' udf just to show you how to use the radiobuttons, the event you were looking for is 'CheckChanged', here is your code modified:
Code:

;Network TRAFFIC LIGHTS (MACE(C)2007) Section 1 of 2 = NTL.kix
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
Global $INIFILE, $WsName[999,1]
$INIFILE="%temp%\PingDomC.ini"
$Script=Split(@SCRIPTNAME,".")
$CMD = @SCRIPTEXE+" "+@scriptdir+"\"+$script[0]+"#2.kix"
If Not Exist($INIFILE)
  Run $CMD
EndIf
;$SCREENWIDTH=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)
;$SCREENHEIGHT=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)

$SCRNW=230
$SCRNH=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)-10
$Form = $System.Form()
$Form.Top=5 ;Position of TOP LEFT from TOP
$Form.Left=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)-$SCRNW ;Position of TOP LEFT from SCREEN LEFT
$Form.Size = $System.Size($SCRNW,$SCRNH) ;(Width,Height)
$Form.Text = @Domain
$Form.maximizebox = "false"
$Form.minimizebox = "false"
$Form.ShowInTaskBar = "False"

$SCRNW=$Form.Width
$SCRNH=($Form.Height)-10

$ListView = $System.ListView()
$ListView.Height = $SCRNH-170
$ListView.Left = 0
$ListView.KeyDown = "KeyDownEvent()"
$ListView.KeyPress = "SelectItemEvent()"
$ListView.Click = "OnClick()"
$ListView.MultiSelect = 0  ;False
$ListView.Sorting = 1  ;Ascending
$ListView.Top = 0
$ListView.Width = $SCRNW
$ListView.View = $System.View_List
$ListView.AutoArrange = "True"
;$ListView.Items.Item(0).Selected = -1 ;True
$nul = $Form.Controls.Add($ListView)

$oDomain = GetObject("WinNT://@LDomain")
$filter = "Computer",""
$oDomain.filter = $filter

$TextBox = $System.TextBox()
$TextBox.Left = 0
$TextBox.Top = $SCRNH-166
$TextBox.Width = $Form.ClientWidth - 35
$nul = $Form.Controls.Add($TextBox)

$OKEnter = $System.Button()
$OKEnter.Click = "OK_Enter()"
$OKEnter.Name = "OKEnter"
$OKEnter.Text = "OK"
$OKEnter.Width = 30
$OKEnter.Left = $Form.ClientWidth-34
$OKEnter.Top = $SCRNH-166
$nul = $Form.Controls.Add($OKEnter)
$Form.AcceptButton = $OKEnter

$RadioBtn0 = $System.radiobutton()
$RadioBtn0.CheckChanged = "ExecTask()"
$RadioBtn0.Left = 7
$RadioBtn0.Text = "WHO is this"
$RadioBtn0.Top = $SCRNH-148
$RadioBtn0.Width = $SCRNW
$RadioBtn0.checked = "True"
$nul = $Form.Controls.Add($RadioBtn0)

$RadioBtn1 = $System.radiobutton()
$RadioBtn1.CheckChanged = "ExecTask()"
$RadioBtn1.Left = 7
$RadioBtn1.Text = "Explore Drive C$"
$RadioBtn1.Top = $SCRNH-130
$RadioBtn1.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn1)

$RadioBtn2 = $System.radiobutton()
$RadioBtn2.CheckChanged = "ExecTask()"
$RadioBtn2.Left = 7
$RadioBtn2.Text = "RDP to Computer"
$RadioBtn2.Top = $SCRNH-112
$RadioBtn2.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn2)

$RadioBtn3 = $System.radiobutton()
$RadioBtn3.CheckChanged = "ExecTask()"
$RadioBtn3.Left = 7
$RadioBtn3.Text = "VNC to Computer"
$RadioBtn3.Top = $SCRNH-94
$RadioBtn3.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn3)

$RadioBtn4 = $System.radiobutton()
$RadioBtn4.CheckChanged = "ExecTask()"
$RadioBtn4.Left = 7
$RadioBtn4.Text = "Restart Computer"
$RadioBtn4.Top = $SCRNH-76
$RadioBtn4.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn4)

$RadioBtn5 = $System.radiobutton()
$RadioBtn5.CheckChanged = "ExecTask()"
$RadioBtn5.Left = 7
$RadioBtn5.Text = "Shutdown Computer"
$RadioBtn5.Top = $SCRNH-58
$RadioBtn5.Width = $SCRNW
$nul = $Form.Controls.Add($RadioBtn5)

$Timer = $System.Timer
$Timer.Interval = 3000 ; msecs
$Timer.Tick = "PingRead"
$Timer.Start
Sleep 2

$Form.AcceptButton = $OnClick
$Form.Show  ;Displays the Form

While $Form.Visible
   $Nul = Execute($Form.DoEvents())
Loop
Del $INIFILE /c /f
Quit()

Function KeyDownEvent()
   $KeyCode = $ListView.KeyDownEventArgs.KeyCode
    If $KeyCode = 37 Or $KeyCode = 38 Or $KeyCode = 39 Or $KeyCode = 40
         $TextBox.Text = $ListView.FocusedItem.Text
   EndIf
   $Form.Activate
EndFunction

Function onclick()
   ;If $ListView.FocusedItem.ForeColor = $System.Color.FromName('Green')
         $TextBox.Text = $ListView.FocusedItem.Text
   ;EndIf
   $Form.Activate
EndFunction

Function SelectItemEvent()
  $TextBox.Text = $ListView.FocusedItem.Text
   If $ListView.KeyPressEventArgs.KeyChar = Chr(13)
   $nul = ExecTask($TextBox.Text)
   EndIf
  $Form.Activate
EndFunction

Function OK_Enter()
  $TextBox.Text = $ListView.FocusedItem.Text
   $nul = ExecTask($TextBox.Text)
  $Form.Activate
EndFunction

Function ExecTask()
; If $ListView.FocusedItem.ForeColor = $System.Color.FromName('Red')
;  $nul= MessageBox("This Unit is currently considered inactive"+chr(10)+chr(10)+"Please select an active Unit.",$NWCompName,16)
; ELSE
   $Computer = @WKSTA
    Select
    Case $RadioBtn0.checked = "True"
    $Nul = WHOIS($Computer)
    Case $RadioBtn1.checked = "True"
    $Nul = Explore($Computer)
    Case $RadioBtn2.checked = "True"
    $Nul = RDP($Computer)
    Case $RadioBtn3.checked = "True"
    $Nul = VNC($Computer)
    Case $RadioBtn4.checked = "True"
    $Nul = RESTART($Computer)
    Case $RadioBtn5.checked = "True"
    $Nul = Shutdown($Computer)
   EndSelect
;endIf
$Form.Activate
EndFunction

Function PingRead();Read in on timer current status of machines.
 $ListView.BeginUpdate
 Dim $ecount, $Count, $a, $Count, $ADD
 If $Ecount < 100  ; If failed to open file # times - exit.
  If Open (8,$INIFILE,2) = 0
   $Count = 0
   $a = ReadLine(8)
   While Not @error
    $Count = $Count + 1
    If $WsName[$count,0] = ""
     $ADD=1
    EndIf
    $linearray = Split($a, ",")
    $x=0
    For Each $element in $Linearray
    $WsName[$Count,$x] = $element
    $x=$x+1
    Next
    If $ADD = 1
     $ = Execute("$$Item$Count = $$ListView.Items.Add($$System.ListViewItem($$WsName[$$Count,0]))")
    EndIf
    If $WsName[$count,1] = "1"
      $ = Execute("$$Item$Count.ForeColor = $$System.Color.FromName('Green')")
    Else
      $ = Execute("$$Item$Count.ForeColor = $$System.Color.FromName('Red')")
    EndIf
   $a = ReadLine(8)
   Loop
   $ = Close(8)
  Else
   $ecount=$ecount+1
  EndIf
  $Total=$Count - 1
 Else
    MessageBox("Unable to open "+$INIFILE+". TERMINATING !","ERROR",16)
    Del $INIFILE /c /f
    Quit()
 EndIf
 $ListView.EndUpdate
EndFunction

Function WHOIS($NWCompName)
  $Query = "Select * from Win32_ComputerSystem"
  $oWMI = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $NWCompName + "\root\cimv2")
  $cItems = $oWMI.ExecQuery($Query)
  For Each $oItem in $cItems
   If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
    $nul= MessageBox("NO ONE IS"+Chr(10)+"LOGGED ON",$NWCompName,64)
    Exit 1
   Else
    $nul= MessageBox(UCase($oItem.UserName),"User on:"+$NWCompName,64)
   EndIf
  Next
EndFunction

Function RDP($NWCompName)
  $cmd = "mstsc.exe /v:"+$NWCompName+":3389 /F"
  Run $cmd
EndFunction

Function VNC($NWCompName)
  $nul= MessageBox("Connect using VNC",$NWCompName,289,30)
;  $cmd = ""
;  RUN $CMD
EndFunction

Function RESTART($NWCompName)
  $MSG='"Emergency CANCEL ='+Chr(10)+'Start + Run then Type'+Chr(10)+'SHUTDOWN -A"'
  $cmd = 'SHUTDOWN -r -f -T 30 -m \\'+$NWCompName+' -c '+$MSG
  Set "SD=$CMD"
  If (MessageBox("This will 'DUMP & KILL' any"+Chr(10)+"current session and will"+Chr(10)+"lose all associated data.","RESTART '"+$NWCompName+"'",305,30)) = 1
   Run $cmd
  EndIf
EndFunction

Function Shutdown($NWCompName)
  $cmd = 'SHUTDOWN -s -f -T 30 -m \\'+$NWCompName+' -c '+$MSG
  If (MessageBox("This will 'DUMP & KILL' any"+Chr(10)+"current session and will"+Chr(10)+"lose all associated data.","SHUTDOWN '"+$NWCompName+"'",305,30)) = 1
   Run $cmd
  EndIf
EndFunction

Function EXPLORE($NWCompName)
  $cmd = 'explorer.exe "\\'+$NWCompName+'\C$"'
  If (MessageBox("This will open the"+Chr(10)+"management C$ share"+Chr(10)+"on this UNIT !","EXPLORE '"+$NWCompName+"'",305,30)) = 1
   Run $cmd
  EndIf
EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Fri May 04, 2007 9:35 pm    Post subject: Reply with quote

I am at a loss how my cut and paste omitted this but it did, my original script reads...
Code:
Function OK_Enter()
  $TextBox.Text = $ListView.FocusedItem.Text
   $nul = ExecTask($TextBox.Text)
  $Form.Activate
EndFunction

Function ExecTask($computer)
...

i.e. The value of $computer is passed to the function when ENTER or OK pressed. following selection of a Computer from the list, which is placed in the $TextBox.Text.
In this case, I really need to update the RadioBtn#.CheckChanged = values just before the case statement and not before as $computer is a variable passed to the function. If it has to be event driven I would use a separate function to set a flag variable with a value indicationg which radio button is current...

Please advise how to balance these requirements...
________
Mercedes-benz 770


Last edited by MACE1 on Fri Feb 18, 2011 5:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri May 04, 2007 9:58 pm    Post subject: Reply with quote

in your first post those lines are there, but you are atempting to pass a value '$Computer' in to your function, you are not seting that variable to any value in your code. if you want $Computer = $TextBox.Text then you have to put that in you code.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Sat May 05, 2007 5:06 pm    Post subject: Reply with quote

I am at a loss on why we are discussing this distraction...
This would appear as a fundamental:

Code:

Break on
$text = "Hello world"
$nul=DISPLAYTEXT($TEXT)
Quit()

Function Displaytext($TheText)
messagebox("This is the text"+chr(10)+"passed into the"+chr(10)+"function:-"+chr(10)+chr(10)+$TheText,"THE TEXT",64)
EndFunction


The desired text DOES get passed into the function in the example and the main code gets its $computer as desired.
What I am trying to ascertain is how best to refresh the radius buttons and check which is the active one.
From what you showed me before, I think I can make an event function set a flag variable which would then be used in the case statement: Unless you can think of a better way ?

Any ideas on the syntax of the RED/GREEN test or listbox index method...
________
Cobalt


Last edited by MACE1 on Sat Mar 12, 2011 5:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Thu Jun 07, 2007 3:05 pm    Post subject: Sorted: Reply with quote

Very Happy
Had a need to use it today so spent a couple of hours debugging and this is the current fully working result. Could not spend time on the RED/Green so I bypassed it and queried the internal array instead.
Code:

;Network TRAFFIC LIGHTS (MACE(C)2007) Section 1 of 2
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
Global $INIFILE, $RADIOX, $WsName[999,1]
$INIFILE="%temp%\PingDomC.ini"
$Script=split(@SCRIPTNAME,".")
$CMD = @SCRIPTEXE+" "+@scriptdir+"\"+$script[0]+"#2.kix"
If not Exist($INIFILE)
  run $CMD
Endif
;$SCREENWIDTH=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)
;$SCREENHEIGHT=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)
$SCRNW=130
$SCRNH=($SYSTEM.SCREEN.WORKINGAREA.BOTTOM)-10
$Form = $System.Form()
;$Form.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form.Top=5 ;Position of TOP LEFT from TOP
$Form.Left=($SYSTEM.SCREEN.WORKINGAREA.RIGHT)-140 ;Position of TOP LEFT from SCREEN LEFT
$Form.Size = $System.Size($SCRNW,$SCRNH) ;(Width,Height)
$Form.Text = @Domain
$Form.maximizebox = "false"
$Form.minimizebox = "false"
$Form.ShowInTaskBar = "False"

$ListView = $System.ListView()
$ListView.Height = $SCRNH-170
$ListView.Left = 0
$ListView.KeyDown = "KeyDownEvent()"
$ListView.KeyPress = "SelectItemEvent()"
$ListView.Click = "OnClick()"
$ListView.MultiSelect = 0  ;False
$ListView.Sorting = 1  ;Ascending
$ListView.Top = 0
$ListView.Width = $SCRNW
$ListView.View = $System.View_List
$ListView.AutoArrange = "True"
;$ListView.Items.Item(0).Selected = -1 ;True
$nul = $Form.Controls.Add($ListView)
$Form.AcceptButton = $OnClick

$oDomain = GetObject("WinNT://@LDomain")
$filter = "Computer",""
$oDomain.filter = $filter

$TextBox = $System.TextBox()
$TextBox.Left = 0
$TextBox.Top = $SCRNH-166
$TextBox.Width = $SCRNW - 35
$nul = $Form.Controls.Add($TextBox)

$OKEnter = $System.Button()
$OKEnter.Click = "OK_Enter()"
$OKEnter.Name = "OKEnter"
$OKEnter.Text = "OK"
$OKEnter.Width = 30
$OKEnter.Left = $SCRNW-34
$OKEnter.Top = $SCRNH-166
$nul = $Form.Controls.Add($OKEnter)
$Form.AcceptButton = $OKEnter

$RadioBtn0 = $System.radiobutton()
$RadioBtn0.Left = 7
$RadioBtn0.Text = "WHO is this"
$RadioBtn0.Top = $SCRNH-148
$RadioBtn0.Width = $SCRNW
$RadioBtn0.checked = "True"
$RadioBtn0.CheckChanged = "Radio(0)"
$nul = $Form.Controls.Add($RadioBtn0)

$RadioBtn1 = $System.radiobutton()
$RadioBtn1.Left = 7
$RadioBtn1.Text = "Explore Drive C$"
$RadioBtn1.Top = $SCRNH-130
$RadioBtn1.Width = $SCRNW
$RadioBtn1.CheckChanged = "Radio(1)"
$nul = $Form.Controls.Add($RadioBtn1)

$RadioBtn2 = $System.radiobutton()
$RadioBtn2.Left = 7
$RadioBtn2.Text = "Explore Drive D$"
$RadioBtn2.Top = $SCRNH-112
$RadioBtn2.Width = $SCRNW
$RadioBtn2.CheckChanged = "Radio(2)"
$nul = $Form.Controls.Add($RadioBtn2)

$RadioBtn3 = $System.radiobutton()
$RadioBtn3.Left = 7
$RadioBtn3.Text = "RDP to Computer"
$RadioBtn3.Top = $SCRNH-94
$RadioBtn3.Width = $SCRNW
$RadioBtn3.CheckChanged = "Radio(3)"
$nul = $Form.Controls.Add($RadioBtn3)

$RadioBtn4 = $System.radiobutton()
$RadioBtn4.Left = 7
$RadioBtn4.Text = "Restart Computer"
$RadioBtn4.Top = $SCRNH-76
$RadioBtn4.Width = $SCRNW
$RadioBtn4.CheckChanged = "Radio(4)"
$nul = $Form.Controls.Add($RadioBtn4)

$RadioBtn5 = $System.radiobutton()
$RadioBtn5.Left = 7
$RadioBtn5.Text = "Shutdown Computer"
$RadioBtn5.Top = $SCRNH-58
$RadioBtn5.Width = $SCRNW
$RadioBtn5.CheckChanged = "Radio(5)"
$nul = $Form.Controls.Add($RadioBtn5)

$Timer = $System.Timer
$Timer.Interval = 3000 ; msecs
$Timer.Tick = "PingRead"
$Timer.Start
sleep 2

$Form.Show  ;Displays the Form
While $Form.Visible
   $Nul = Execute($Form.DoEvents())
Loop
del $INIFILE /c /f
Quit()

Function KeyDownEvent()
   $KeyCode = $ListView.KeyDownEventArgs.KeyCode
   ;? $KeyCode ;for testing pruposes show the char pressed 37 = Left Arrow, 38 = Up Arrow, 39 = Right Arrow, 40 = Down Arrow
   If $KeyCode = 37 Or $KeyCode = 38 Or $KeyCode = 39 Or $KeyCode = 40
         $TextBox.Text = $ListView.FocusedItem.Text
   EndIf
   $Form.Activate
EndFunction

Function onclick()
   ;If $ListView.FocusedItem.ForeColor = $System.Color.FromName('Green')
         $TextBox.Text = $ListView.FocusedItem.Text
   ;EndIf
   $Form.Activate
EndFunction

Function SelectItemEvent()
  $TextBox.Text = $ListView.FocusedItem.Text
   If $ListView.KeyPressEventArgs.KeyChar = chr(13)
   $nul = ExecTask($TextBox.Text)
   Endif
  $Form.Activate
EndFunction

Function OK_Enter()
  $TextBox.Text = $ListView.FocusedItem.Text
   $nul = ExecTask($TextBox.Text)
  $Form.Activate
EndFunction

Function Radio($RadioBtn)
 $RADIOX = $Radiobtn
EndFunction

Function ExecTask($Computer)
 For $X = 1 to $Total
 if $WsName[$X,0] = $Computer
  If $WsName[$X,1] = "1"
   SELECT
    Case $RADIOX = 0
    $Nul = WHOIS($Computer)
    Case $RADIOX = 1
    $Nul = Explore($Computer,"C$")
    Case $RADIOX = 2
    $Nul = Explore($Computer,"D$")
    Case $RADIOX = 3
    $Nul = RDP($Computer)
    Case $RADIOX = 4
    $Nul = RESTART($Computer)
    Case $RADIOX = 5
    $Nul = SHUTDWN($Computer)
   EndSelect
  Else
   $TextBox.Text = ""
  endIf
 Endif
 Next
$Form.Activate
EndFunction

Function PingRead();Read in on timer current status of machines.
 $ListView.BeginUpdate
 Dim $ecount, $Count, $a, $Count, $ADD
 If $Ecount < 100  ; If failed to open file # times - exit.
  If Open (8,$INIFILE,2) = 0
   $Count = 0
   $a = readline(8)
   WHILE NOT @error
    $Count = $Count + 1
    if $WsName[$count,0] = ""
     $ADD=1
    Endif
    $linearray = Split($a, ",")
    $x=0
    For each $element in $Linearray
    $WsName[$Count,$x] = $element
    $x=$x+1
    next
    IF $ADD = 1
     $ = execute("$$Item$Count = $$ListView.Items.Add($$System.ListViewItem($$WsName[$$Count,0]))")
    Endif
    if $WsName[$count,1] = "1"
      $ = execute("$$Item$Count.ForeColor = $$System.Color.FromName('Green')")
    Else
      $ = execute("$$Item$Count.ForeColor = $$System.Color.FromName('Red')")
    Endif
   $a = readline(8)
   LOOP
   $ = Close(8)
  Else
   $ecount=$ecount+1
  Endif
  $Total=$Count - 1
 Else
    Messagebox("Unable to open "+$INIFILE+". TERMINATING !","ERROR",16)
    del $INIFILE /c /f
    Quit()
 Endif
 $ListView.EndUpdate
EndFunction

FUNCTION WHOIS($NWCompName)
  $Query = "Select * from Win32_ComputerSystem"
  $oWMI = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $NWCompName + "\root\cimv2")
  $cItems = $oWMI.ExecQuery($Query)
  For Each $oItem In $cItems
   If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
    exit 1
   Else
    If len($oItem.UserName) >1
     $nul= MessageBox(ucase($oItem.UserName),"User on:"+$NWCompName,64)
    Else
     $nul= MessageBox("NOT CURRENTLY IN USE","NO User on "+$NWCompName,64)
    Endif
   EndIf
  Next
ENDFUNCTION

FUNCTION RDP($NWCompName)
  $cmd = "mstsc.exe /v:"+$NWCompName+":3389 /F"
  RUN $cmd
ENDFUNCTION

FUNCTION RESTART($NWCompName)
  $MSG='"Emergency CANCEL ='+chr(10)+'Start + Run then Type'+chr(10)+'SHUTDOWN -A"'
  $cmd = 'SHUTDOWN -r -f -T 30 -m \\'+$NWCompName+' -c '+$MSG
  set "SD=$CMD"
  if (MessageBox("This will 'DUMP & KILL' any"+chr(10)+"current session and will"+chr(10)+"loose all associated data.","RESTART '"+$NWCompName+"'",305,30)) = 1
   RUN $cmd
  Endif
ENDFUNCTION

FUNCTION SHUTDWN($NWCompName)
  $cmd = 'SHUTDOWN -s -f -T 30 -m \\'+$NWCompName+' -c '+$MSG
  if (MessageBox("This will 'DUMP & KILL' any"+chr(10)+"current session and will"+chr(10)+"loose all associated data.","SHUTDOWN '"+$NWCompName+"'",305,30)) = 1
   RUN $cmd
  Endif
ENDFUNCTION

FUNCTION EXPLORE($NWCompName,$DRV)
  $cmd = 'explorer.exe "\\'+$NWCompName+'\'+$DRV+'"'
  if (MessageBox("This will attempt to open"+chr(10)+"the management "+$DRV+" share"+chr(10)+"on this UNIT !","EXPLORE '"+$NWCompName+"'",305,30)) = 1
   RUN $cmd
  Endif
ENDFUNCTION


This is Part 1 of 2. Part 2 has not changed.

For ease the WHOIS function is basic NT.
I want to use an Active Directory Query to return both the Username and the Fully Qualified First Name + Surname but as yet have failed miserably in formatting it correctly. Help would be appreciated with this.

Does anyone have examples of how the indexing of the listbox items works so I don't have to double up the data with an array ?
Similarly how to test for the listbox item colour ?
________
MEDICAL MARIJUANA DOCTOR
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group