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

Find by computer name and who has logged into

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Feb 03, 2004 9:19 pm    Post subject: Find by computer name and who has logged into Reply with quote

This code works best if you have a uniform way of naming computers within your network.

We have a numbering scheme that uses the 3 letter airport code and then an 8 character #. We use Inventory Control Numbers.

This particular code takes the last 8 characters and searches all domains to find the computer specified and returns a DIR list that shows who has logged into that computer.

Many thanks to Sealeopard for the ComNetView function and to one of Shawn's demo's on how to put info into the text box.

As usual critique and suggestions are alway's welcome.

Code:
cls
SetConsole (Hide)
Break On
$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.Height = 245
$Form.Left = 22
$Form.MaximizeBox = "False"
$Form.MinimizeBox = "False"
$Form.Text = "Find Machine"
$Form.Top = 22
$Form.Width = 303
;**************************************

;************* lbl_info1 **************
$lbl_info1 = $Form.Controls.Label()
$lbl_info1.BackColor = 212,208,200
$lbl_info1.Height = 18
$lbl_info1.Left = 0
$lbl_info1.Text = "Please Enter ICN #"
$lbl_info1.Top = 0
$lbl_info1.Width = 116
;**************************************

;************* TxtBx_input **************
$TxtBx_input = $Form.Controls.TextBox()
$TxtBx_input.Height = 20
$TxtBx_input.Left = 135
$TxtBx_input.MaxLength = 8
$TxtBx_input.Text = ""
$TxtBx_input.Top = 0
$TxtBx_input.Width = 100
;**************************************

;************* btn_start **************
$btn_start = $Form.Controls.Button()
$btn_start.Height = 23
$btn_start.Left = 0
$btn_start.Text = "Search"
$btn_start.Top = 30
$btn_start.Width = 75
$btn_start.OnClick = "Search()"
;**************************************

;************* btn_exit **************
$btn_exit = $Form.Controls.Button()
$btn_exit.Height = 23
$btn_exit.Left = 150
$btn_exit.Text = "Exit"
$btn_exit.Top = 30
$btn_exit.Width = 75
$btn_exit.OnClick = "exitjob()"
;**************************************

;************* TxtBx_results **************
$TxtBx_results = $Form.Controls.TextBox()
$TxtBx_results.Height = 124
$TxtBx_results.Left = 0
$TxtBx_results.Multiline = "True"
$TxtBx_results.ReadOnly = "True"
$TxtBx_results.ScrollBars = 2
$TxtBx_results.Text = ""
$TxtBx_results.Top = 90
$TxtBx_results.Width = 291
;**************************************

;************* lbl_results **************
$lbl_results = $Form.Controls.Label()
$lbl_results.BackColor = 212,208,200
$lbl_results.Height = 21
$lbl_results.Left = 0
$lbl_results.Text = ""
$lbl_results.Top = 60
$lbl_results.Width = 235
;**************************************


;KD END
  Global $Computer
;Enter your Domains below to create an array.
  $DomList =
  SetOption("NoVarsInStings", "On")
  $txtbx_input.setfocus ()

$Form.Show


Function ExitJob()
  Quit ()
EndFunction

Function Search()
  $txtbx_results.text = ""

  For each $Domain in $DomList
  $lbl_results.Text = "Now Searching "+$Domain
    COMNetView ($Domain)
  Next

  If $txtbx_results.text = ""
    $lbl_results.text = "Not Found"
    $txtbx_input.text = ""
   Else
    $lbl_results.text = "Users found on "+$Computer + ":  Listing Complete"
    $txtbx_input.text = ""
  Endif

  $txtbx_input.setfocus ()
endFunction



FUNCTION      COMNetView($Domain)

  Dim $list, $objDomain, $objComputername, $filter[0]

  if val(@INWIN)<>1 or val(@DOS)<5   
    exit 196 
  endif 
  $domain = trim($domain) 
  if $domain=''   
    $domain=@DOMAIN 
  endif 
  $filter[0]='Computer' 
  $objDomain = GetObject('WinNT://' + $domain + ',domain') 
 

  if @ERROR   
    exit @ERROR 
  endif  $objDomain.Filter=$filter 

  if @ERROR   
    exit @ERROR 
  endif 
  For Each $objComputername In $objDomain   
    redim preserve $list[ubound($list)+1]   
    $list[ubound($list)] = $objComputername.Name 
  Next 
  $objDomain = 0 


  For Each $element in $list
   if $txtbx_input.text = Right($element, 8)
      $Array = WSHPipe("cmd /c dir \\"+$Element+"\c$$\docume~1 /b")
      For Each $Line In $Array
      $txtbx_results.Text = $txtbx_results.Text + $Line
     $txtbx_results.Text = $txtbx_results.Text + @CRLF
      Next
     $Computer = $element
    Endif
  Next

  exit @ERROR
EndFunction

Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
   Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode
   $WshErrorMsg=""
   $WshShell=CreateObject("WScript.Shell")
   $oExec=$WshShell.Exec($ShellCMD)
   While $Exit<>1
      Dim $Output
      Select
      Case Not $oExec.StdOut.AtEndOfStream
         $Output=$oExec.StdOut.ReadAll
      Case Not $oExec.StdErr.AtEndOfStream
         $Output=$oExec.StdErr.ReadAll
         $WshErrorMsg = $Output
      Case 1
         $Output=-1
      EndSelect
      If $Output=-1
         If $oExec.Status=1
            $Exit=1
         Endif
      Else
         If $NoEcho<>1
            ? $Output
         Endif
         $AllOutput = $AllOutput + $Output
      Endif
   Loop
   $WshExitCode=$oExec.ExitCode
   $WshPipe=split($AllOutput,chr(10))
   $oExec.Quit
   Exit($WshExitCode)
EndFunction Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
   Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode
   $WshErrorMsg=""
   $WshShell=CreateObject("WScript.Shell")
   $oExec=$WshShell.Exec($ShellCMD)
   While $Exit<>1
      Dim $Output
      Select
      Case Not $oExec.StdOut.AtEndOfStream
         $Output=$oExec.StdOut.ReadAll
      Case Not $oExec.StdErr.AtEndOfStream
         $Output=$oExec.StdErr.ReadAll
         $WshErrorMsg = $Output
      Case 1
         $Output=-1
      EndSelect
      If $Output=-1
         If $oExec.Status=1
            $Exit=1
         Endif
      Else
         If $NoEcho<>1
            ? $Output
         Endif
         $AllOutput = $AllOutput + $Output
      Endif
   Loop
   $WshExitCode=$oExec.ExitCode
   $WshPipe=split($AllOutput,chr(10))
   $oExec.Quit
   Exit($WshExitCode)
EndFunction

While $Form.Visible
   $=Execute($Form.DoEvents())
Loop
Exit 1


Created with KixStart 4.21
Kix Forms 2.3.0 Beta 4
Kix Forms Designer 1.0 Beta 3

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive 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