Jump to content
Sign in to follow this  
jvanegmond

Share Watcher

Recommended Posts

Based on Ibraham's script: 

Put the attached icon.ico file in the same directory as the script.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.9.2 (beta)
 Author:         Jos van Egmond

 Script Function:
    This is a script that watches your net sessions. It will Tray Tip the currently open connections.

#ce ----------------------------------------------------------------------------

Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)

#include <Constants.au3>
#include <Array.au3>

TraySetIcon("icon.ico")

TraySetToolTip("Share Watcher")

$tExit = TrayCreateItem("Exit")
TrayItemSetOnEvent($tExit,"Close")

While 1
    $sSessions = GetSessions()
    If Not @error Then
        TrayTip("Share Watcher", $sSessions,5)
    EndIf
    Sleep(1000)
WEnd

Func GetSessions()
    Local $sBuffer = "", $sReturn = ""
    $pPID = Run("net session","",@SW_HIDE,$STDOUT_CHILD)
    While 1
        $sBuffer &= StdoutRead($pPID)
        If @error Then ExitLoop
    WEnd
    $sSplit = StringSplit(StringStripCR($sBuffer),@LF)
    If $sSplit[0] > 3 Then
        For $x = 1 to $sSplit[0]
            If StringLeft($sSplit[$x],2) = "\\" Then
                $sTemp = StringSplit($sSplit[$x],"  ",1)
                $sTemp = _ArrayDeleteEmpty($sTemp)
                ;_ArrayDisplay($sTemp)
                $sReturn &= $sTemp[2] & " on computer " & StringTrimLeft($sTemp[1],2) & " is looking." & @CRLF
            EndIf
        Next
        $sReturn = StringTrimRight($sReturn,2)
    Else
        Return SetError(1,0,0)
    EndIf
    Return $sReturn
EndFunc

Func _ArrayDeleteEmpty($aArray)
    Local $aReturn[1], $i = 0
    For $x = 0 to UBound($aArray)-1
        If $aArray[$x] <> "" Then
            $aReturn[$i] = $aArray[$x]
            $i += 1
            ReDim $aReturn[$i+1]
        EndIf
    Next
    Return $aReturn
EndFunc

Func Close()
    Exit
EndFunc
Edited by jvanegmond

Share this post


Link to post
Share on other sites

Well Thank you for saying my NAME, I did it with the help of Smashly too ,I did so Little thing i know it's not that great but it's a must,it doesn't block viewing the files but it terminate Copy procedure.Or it can be put in the loop to keep blocking it

here it's

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.9.2 (beta)
 Author:         Manadar

 Script Function:
    This is a script that watches your net sessions. It will Tray Tip the currently open connections.

#ce ----------------------------------------------------------------------------

Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)

#include <Constants.au3>
#include <Array.au3>
$I=1

TraySetIcon($I&".ico")

TraySetToolTip("Share Watcher")

$tExit = TrayCreateItem("Exit")
$Kill=TrayCreateItem("Terminate Session");<<<<<<<<<<<<-----------------------------------------
TrayItemSetState($Kill,$TRAY_DISABLE)
TrayItemSetOnEvent($tExit,"Close")
TrayItemSetOnEvent($Kill,"Terminate")
While 1
    $sSessions = GetSessions()
    If Not @error Then
        AnimateIcon();<<<<<<<<<<<<-----------------------------------------
        TrayTip("Share Watcher", $sSessions,5)
        TrayItemSetState($Kill,$TRAY_ENABLE);<<<<<<<<<<<<-----------------------------------------
    EndIf
    
    Sleep(500)
    TraySetIcon("1.ico")
    
WEnd

Func AnimateIcon();<<<<<<<<<<<<-----------------------------------------
    For $I=1 to 4
        sleep(500)
    TraySetIcon($I&".ico")
Next
EndFunc
    
Func GetSessions()
    Local $sBuffer = "", $sReturn = ""
    $pPID = Run("net session","",@SW_HIDE,$STDOUT_CHILD)
    While 1
        $sBuffer &= StdoutRead($pPID)
        If @error Then ExitLoop
    WEnd
    $sSplit = StringSplit(StringStripCR($sBuffer),@LF)
    If $sSplit[0] > 3 Then
        For $x = 1 to $sSplit[0]
            If StringLeft($sSplit[$x],2) = "\\" Then
                $sTemp = StringSplit($sSplit[$x],"  ",1)
                $sTemp = _ArrayDeleteEmpty($sTemp)
             ;_ArrayDisplay($sTemp)
                $sReturn &= $sTemp[2] & " on computer " & StringTrimLeft($sTemp[1],2) & " is looking." & @CRLF
            EndIf
        Next
        $sReturn = StringTrimRight($sReturn,2)
    Else
        Return SetError(1,0,0)
    EndIf
    Return $sReturn
EndFunc

Func _ArrayDeleteEmpty($aArray)
    Local $aReturn[1], $i = 0
    For $x = 0 to UBound($aArray)-1
        If $aArray[$x] <> "" Then
            $aReturn[$i] = $aArray[$x]
            $i += 1
            ReDim $aReturn[$i+1]
        EndIf
    Next
    Return $aReturn
EndFunc

Func Close()
    Exit
EndFunc
Func Terminate();<<<<<<<<<<<<-----------------------------------------
   Run("net session /delete")
EndFunc

Hope u like it

Edit Added Animated icons(Should be included) and i guess i shoulf have put this in a Dll file but wait till finished i guess.!

1.ico

2.ico

3.ico

4.ico

Edited by Melba23
User name removed by request

Share this post


Link to post
Share on other sites

This is nice, but remember, many users have balloon tips disabled. I do, and all I got was DING! DING! DING! and all my regular tray tips disabled.

TraySetToolTip always works (afaik) but is limited to 128 chrs, rather than 255. I switched it to this, and almsot got a full three lines in my tip. Without the "on computer" part in the text, I got three full lines no problem. It's okay to put linefeeds in regular tray tips, too.

Definitely handy, but without the DING!

;o)

(or


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

to those with balloon tips disabled do this

navigate to Regedit

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced

search for a Dword named Balloontipsenabled and set it to 1

Balloon tips are way better the message boxes

Share this post


Link to post
Share on other sites

Erm, no. They are disabled for a REASON! And they will stay that way!

And anyone who has disabled them, is probably well aware how to enable them again!

Who said anything about message boxes? I'm referring to TraySetToolTip().

Check your AutoIt manual.

;o)

(or


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

Any Body figured out how to query data from active directory share Session part.It's more fast, less DOS and most of all not all machines can tolerate dos output every 1-5 seconds,So active directory query will fit better and Appropriate.

Share this post


Link to post
Share on other sites

just paste this line in the while wend loop After traytip

$filepath="c:\sharewatcher.log"

FileWriteLine($filePath,@HOUR&":"&@MIN&"----->"&$sSessions)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...