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

FindFile - searches remote PCs for a specific file

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


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Sat Mar 15, 2003 12:47 pm    Post subject: FindFile - searches remote PCs for a specific file Reply with quote

Returns PCs with the file and it's version
Ability to export listbox to CSV




Code:

BREAK ON
;$=setconsole("minimize")
$=setconsole("hide")

;********************************************************************
;********************************************************************
$ldap="LDAP://wheelerfam/dc=wheelerfam,dc=net"         ; ***
$kixformsdir=""                     ; ***
;********************************************************************
;********************************************************************


; *********************** Register Kixforms *************************
:top
if VersionCompare(getfileversion("%windir%\kixforms.dll"), "<", "2.2.0.37")
   copy "$kixformsdir\kixforms.dll" %windir%
   endif
$FORM = CREATEOBJECT("Kixtart.FORM")
if not $form
   shell 'regsvr32 /s %windir%\kixforms.dll'
   goto top
   endif

; *********************** FORM Start ********************************
$Form.ClientWidth   = 500
$Form.ClientHeight   = 550
$Form.FontName      = Arial
$Form.FontSize      = 10
$Form.Text      = "FileFinder"

$Form.PrintXY(10,15,"Computer OUs:")
$txtArea      = $Form.ComboBox
$txtArea.Bounds      = 110,10,380,150
$txtArea.Style      = 1
$txtArea.DropDownWidth   = 350
$txtArea.onClick   = "EnableSearch()"

$Form.PrintXY(10,$txtArea.bottom + 13,"Full Path to File:")
$txtFile       = $form.TextBox
$txtFile.Bounds    = 110,$txtArea.bottom + 10,380,25
$txtFile.onChange   = "EnableSearch()"

$Search       = $Form.ToolButton
$Search.Icon      = 43
$Search.Bounds      = 10,$txtFile.Bottom +10, 90, 25
$Search.Text       = "Search"
$Search.ToolTip    = "Search OU for File"
$Search.OnClick    = "Search_Click()"

$Export       = $Form.ToolButton
$Export.Icon      = 3
$Export.Bounds      = $Form.Clientwidth -90 -10 ,$txtFile.Bottom +10, 90, 25
$Export.Text       = "Export"
$Export.ToolTip    = "Export results to a file"
$Export.OnClick    = "Export_Click()"

$prgBar       = $Form.ProgressBar("",$Search.right +10,$Search.Top,280,25)
$prgBar.Style = 1

$List         = $Form.ListView()
$List.Bounds      = 10,$Search.bottom +10,480,$Form.ClientHeight - ($Search.bottom + 20)
$List.Sorted      = 1
$List.MultiSelect   = True
$List.GridLines      = True
$List.View      = 3   
$List.FullRowSelect   = True 
$List.OnClick      = ""


;********************************************************************************************
;**************         Start the application ...            *************
;********************************************************************************************

$Search.enabled      = 0
$Export.enabled      = 0
$txtArea.ListIndex   = 0

$ou = EnumOUs($ldap, 'computer')
for each $item in split($ou,"|")
   $txtArea.AddItem($item)
   next

$_ = $List.Columns.Add("PC Name")
$_ = $List.Columns.Add("Version")
For Each $Column In $List.Columns
   $Column.Width = ($List.ClientWidth-15) / $List.Columns.Count
   Next

$Form.Center
$Form.Show

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

;*****************************************************************************
;**************         Start the UDF Section ...         *************
;*****************************************************************************
Function EnumOUs($LDAP, $Filter)
   dim $aFilter[0], $pos,  $objOU, $i, $j
   if $Filter <> 'user'
      $Filter = 'computer'
      endif
   $objOU = GetObject($LDAP)
   if VarTypeName($objOU)='Object'
      $aFilter[0] = $Filter
      $objOU.Filter = $aFilter
      for each $item in $objOU
         if $item.class = $Filter
            $i = $LDAP
            endif
         next
      $aFilter[0] = "organizationalUnit"
      $objOU.Filter = $aFilter
      for each $item in $objOU
         $Name = $item.Name
         $pos = instrrev($LDAP,"/")
         $DN = Left($LDAP,$pos) + $Name + ", " + substr($LDAP, $pos+1)
         $j = EnumOUs($DN, $Filter)
         if $j
            if $i
               $i = $i +"|"+ $j
            else
               $i = $j
               endif
            endif
         next
   else
   ;      ? "GetObject COM error: " + @error + " " + @serror
      exit 1
      endif
    $EnumOUs = $i
   Endfunction
;****************************************************************************
Function EnableSearch()
   if $txtFile.text >" " and $txtArea.text  >" "
      $Search.enabled      = 1
      endif
   endfunction
;****************************************************************************
Function Search_Click()
   dim $computers, $name, $cn, $count, $max
   $area=$txtArea.text
   $Computers = GetObject($area)
   $max=0   for each $c in $computers   $max=$max+1   next
   $List.setfocus
   $count=0
   For each $Item in $computers
      $cn=$Item.name
      $name=right($cn, len($cn)-3)
      $count=$count + 1
      $prgBar.value= ($count * 100) / $max
      if wshping($name)[0]
         $remotefile='\\'+$name+'\c$$'+split($txtFile.text,':')[1]
         if exist($remotefile)
            $ver=getfileversion($remotefile)
            $Item = $List.Items.Add($Name)
            $Item.SubItems(1).Text=$ver
            endif
         endif
      NEXT
   $prgbar.value   = 0
   $computers   = 0
   $Search.enabled   = 0
   $Export.enabled   = 1
   endfunction
;****************************************************************************
Function Export_Click()
   $Path=split($txtFile.text,'\')
   $ExportFile=$Path[ubound($path)] +'.csv'
   $ExportDir='%USERPROFILE%\desktop'
   $=open(1,'$exportdir\$exportfile',5)
   if not @error
      for each $item in $list.items
         $pc=$item.text
         $ver=$item.SubItems(1).Text
         $=writeline(1,'$pc,$ver'+@crlf)
         next
      $=close(1)
      endif
   $list.items.clear
   $Export.enabled   = 0
   endfunction
;********************************************************************************************************
FUNCTION WSHPing($Computer,optional $replies)
   dim $ip, $l, $r, $count, $return, $line ,$pos, $avg
   if not $replies      $replies=1   endif
   $ip=$computer      $Count=0
   $shell='%comspec% /c %windir%\system32\ping $Computer -n $replies '
   $return=WSHPipe($shell,1)
   if not @error
      for each $line in $return
         select
            case instr($line,"[")      $l=instr($line,"[")+1
                        $r=instr($line,"]")
                        $ip=substr($line,$l,$r-$l)
            case instr($line,"reply from")   $Count=$Count+1
            case instr($line,"Average")   $pos=instr($line,"Average")+8
                        $avg=val(right("$line",len($line)-$pos))
            endselect
         if instr($line,"timed out")   $Count=$Count-1      endif
         next
      $WSHPing=$ip,$count,$avg
   else
      $WSHPing="0.0.0.0","0","0"
      exit(487)
      endif
   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))
   Exit($WshExitCode)
   EndFunction
;****************************************************************************
function VersionCompare($Ver1, $Comparison, $Ver2, OPTIONAL $Limit)
   dim $Ver1Sep, $Ver2Sep, $Ver1A, $Ver2A, $SegIndex
   $Limit=0+$Limit
   if $Limit=0 or $Limit>4
      $Limit=4
      endif
   $Ver1=''+$Ver1
   $Ver2=''+$Ver2
   if $Ver1='' or $Ver2='' or $Comparison=''
      $VersionCompare=''
      return
      endif
   if instr($Ver1,',')
      $Ver1Sep=','
   else
      $Ver1Sep='.'
      endif
   if instr($Ver2,',')
      $Ver2Sep=','
   else
      $Ver2Sep='.'
      endif
   $Ver1=$Ver1+$Ver1Sep+$Ver1Sep+$Ver1Sep+$Ver2Sep   
   $Ver2=$Ver2+$Ver2Sep+$Ver2Sep+$Ver2Sep+$Ver2Sep
   $Ver1A=split($Ver1,$Ver1Sep)
   redim preserve $Ver1A[$Limit-1]
   $Ver2A=split($Ver2,$Ver2Sep)
   redim preserve $Ver2A[$Limit-1]
   $Ver1A[0]=right(''+'0000'+$Ver1A[0],4)
   $Ver2A[0]=right(''+'0000'+$Ver2A[0],4)
   for $SegIndex = 1 to $Limit-1
      $Ver1A[$SegIndex]=left(''+trim($Ver1A[$SegIndex])+'0000',4)
      $Ver2A[$SegIndex]=left(''+trim($Ver2A[$SegIndex])+'0000',4)
      next
   $Ver1=Join($Ver1A,'.')
   $Ver2=Join($Ver2A,'.')
   select
      case instr($Comparison,'=') and $Ver1=$Ver2      $VersionCompare=1
      case instr($Comparison,'<') and $Ver1<$Ver2      $VersionCompare=1
      case instr($Comparison,'>') and $Ver1>$Ver2      $VersionCompare=1
      case 1                      $VersionCompare=0
      endselect
   endfunction

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Mar 22, 2003 3:14 am    Post subject: Reply with quote

uuh!
nice idea allthough AD-aware so can't use.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Sat Mar 22, 2003 9:34 am    Post subject: Reply with quote

you can use EnumDHCP() to base it on subnets, with a little modification...
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Mar 22, 2003 5:12 pm    Post subject: Reply with quote

dhcp?
uhm...
I think I would go with wins-approach.
anyway, not gonna do that as no need to search for files Wink
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Mar 22, 2003 5:14 pm    Post subject: Reply with quote

and the investor btw did it basically already...
it just searched for installed softwares but the idea is same.

this script I might use as a base once get on the AD side though...
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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