Jump to content
Sign in to follow this  
jvanegmond

Share Watcher

Recommended Posts

jvanegmond

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
gseller

Cool, I 'll have to take this to work to checkit out.. LOL Looks pretty nice..

Share this post


Link to post
Share on other sites
Ibrahim

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
jvanegmond

Ibrahim, I really like the moving icons, but I think you can make it simpler. I'll look into that later.

I don't even think the net session /delete command disallows another user to view your files. They will just open a new connection.

Share this post


Link to post
Share on other sites
corz

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
Ibrahim

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
corz

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
Ibrahim

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
LordSphynx

Ibrahim,

Could you make an option to write the sessions to a logfile ? That would come in handy !

Share this post


Link to post
Share on other sites
Ibrahim

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
Hellooopsforgotsendcommand

Based on Ibraham's script: This is a more advanced version, with the looks to prove it.

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

What attached icon file! there is only a script to copy and paste.

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  

×