Marc Posted January 25, 2005 Share Posted January 25, 2005 Hi, at my day job we're using a standard Windows 2000 PC which offers some file shares to our department. Sadly, only 10 connections at the same time are allowed. To get more, we would have to buy a W2k Server license. Would be the most expensive solution to this problem, since the share does not have to be connected permanently, its just used as some kind of data exchange directory. Found out that several people have connected the shares permanently and/or keep a window open without doing anything in it. So I wrote a small script which uses the "net session" command to find out how long the users have been idle and removes the idling ones This version works fine on a german w2k system, perhaps the output format of an english version of "net session" would be different, but I doubt that. expandcollapse popup; Language: AutoIt 3.0.103 ; Autor : M.R.Delhalle ; Datum : 2004-09-15 #include<process.au3> #include<file.au3> Opt("TrayIconDebug",1) $datei = @TempDir & "\netsession.txt" while 1 ; List all connected users in tempfile _rundos("net session >" & $datei) $file = FileOpen($datei, 0) If $file = -1 Then MsgBox(0, "Error", "Could not create temporary file for net session") Exit EndIf if FileGetSize($datei)>50 then check(); some shares seem to exist FileClose($datei) FileDelete($datei) sleep (300000); 5 min Pause Wend Func check() $counter = 0 ; Read file and search for connected users do $line = FileReadLine($file) Until StringInStr($line, "------------") > 0 While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $time = StringMid($line, 69) ; extrat time entry from current line $timesplit = StringSplit($time,":"); split into hours and minutes if ($timesplit[0]=3) and (($timesplit[1] > 0) or ($timesplit[2]>10)) Then; disconnect after 10 minutes $computer = StringStripWS(StringLeft($line, 22),2) ; tricky: echo y = answer yes to the requester ; in german OS replace the "y" with a "j" _rundos("echo y|net session " & $computer & " /delete") $counter=$counter + 1 EndIf Wend if $counter>0 then TrayTip ( "Removed connected user", "Successfully disconnected " & $counter & " user(s)", 5 ) EndFunc By the way, this script is in use for over 4 month now and since it runs, I never ever had a team mates request to remove other users manually, which happened four times a day before... Best regards, Marc Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
kpu Posted January 25, 2005 Share Posted January 25, 2005 I like it! I will be adding this to my collection http://www.kpunderground.com Link to comment Share on other sites More sharing options...
DirtyBanditos Posted January 25, 2005 Share Posted January 25, 2005 Hi,at my day job we're using a standard Windows 2000 PC which offers some file shares to our department. Sadly, only 10 connections at the same time are allowed. To get more, we would have to buy a W2k Server license.Would be the most expensive solution to this problem, since the share does not have to be connected permanently, its just used as some kind of data exchange directory.Found out that several people have connected the shares permanently and/or keep a window open without doing anything in it.So I wrote a small script which uses the "net session" command to find out how long the users have been idle and removes the idling ones This version works fine on a german w2k system, perhaps the output format of an english version of "net session" would be different, but I doubt that.expandcollapse popup; Language: AutoIt 3.0.103 ; Autor : M.R.Delhalle ; Datum : 2004-09-15 #include<process.au3> #include<file.au3> Opt("TrayIconDebug",1) $datei = @TempDir & "\netsession.txt" while 1 ; List all connected users in tempfile _rundos("net session >" & $datei) $file = FileOpen($datei, 0) If $file = -1 Then MsgBox(0, "Error", "Could not create temporary file for net session") Exit EndIf if FileGetSize($datei)>50 then check(); some shares seem to exist FileClose($datei) FileDelete($datei) sleep (300000); 5 min Pause Wend Func check() $counter = 0 ; Read file and search for connected users do $line = FileReadLine($file) Until StringInStr($line, "------------") > 0 While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $time = StringMid($line, 69) ; extrat time entry from current line $timesplit = StringSplit($time,":"); split into hours and minutes if ($timesplit[0]=3) and (($timesplit[1] > 0) or ($timesplit[2]>10)) Then; disconnect after 10 minutes $computer = StringStripWS(StringLeft($line, 22),2) ; tricky: echo y = answer yes to the requester ; in german OS replace the "y" with a "j" _rundos("echo y|net session " & $computer & " /delete") $counter=$counter + 1 EndIf Wend if $counter>0 then TrayTip ( "Removed connected user", "Successfully disconnected " & $counter & " user(s)", 5 ) EndFuncBy the way, this script is in use for over 4 month now and since it runs, I never ever had a team mates request to remove other users manually, which happened four times a day before... Best regards,Marc<{POST_SNAPBACK}>Hello thx To Share it Out, great job can i adde it on my forum wis your credits to it? Link to comment Share on other sites More sharing options...
Marc Posted January 26, 2005 Author Share Posted January 26, 2005 @kpu: thanks @DirtyBanditos: Of course, do as you see fit Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
DirtyBanditos Posted January 26, 2005 Share Posted January 26, 2005 @kpu: thanks @DirtyBanditos: Of course, do as you see fit <{POST_SNAPBACK}>Hello Mark Ok one thanks Mark I gives naturally credit to the author! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now