Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


check connections to your shared folders

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,29976
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> check connections to your shared folders
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 check connections to your shared folders - 1/17/2006 3:38:06 AM   
  red_phender


Posts: 9
Score: 0
Joined: 1/17/2006
Status: offline
I just wrote this to check if any curious admin is connected to my shared folders. The script can echo the result to the screen (you'd better use cscript) or write on a text file that is created calling another script I include.

Here you are

'****************************************************************************************
' Script : CheckActiveConnections.vbs
' Date : Dec, 28th 2005
' Description: checks if there're active connections to local shares
' Usage:
' Cscript CheckActiveConnections.vbs [/L]
' Parms:
' /L - optional - use log file to write the result. The log file is
' automatically created calling the script CreateLogFile.vbs. If the
' /L switch in not specified in the command line the result is echoed
' to the screen
' Version : 1.0
'****************************************************************************************

strComputer = "."
CONST ForReading = 1, ForWriting = 2, ForAppending = 8

Set objfso=CreateObject("scripting.filesystemobject")
Set f = objfso.GetFile(wscript.scriptfullname)
runpath=f.parentfolder & "\"
ArgNum=wscript.arguments.count
set namedarguments=WScript.Arguments.Named
if ucase(namedarguments.exists("L")) then
uselog=vbtrue
set objShell = CreateObject("WScript.Shell")
execstring="wscript.exe //B c:\documenti\scripts\createlogfile.vbs /F:""" & f.name & """" & " /P:""" & f.parentfolder & """"
set r=objshell.exec(execstring)
Do While r.Status = 0
WScript.Sleep 100
Loop
logfilename=runpath & f.name & ".log"
Set objLogFile = objFSO.OpenTextFile(logfilename, ForAppending)
else
uselog=vbfalse
end if

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ServerConnection")

if uselog = vbtrue then
objlogfile.writeline(vbcrlf & date() & " " & time() & vbcrlf & "Number of active connections: " & colitems.count & vbcrlf)
else
wscript.echo "------ " & f.name & " Start " & date & " " & time() &" -----" & vbcrlf
wscript.echo date() & " " & time() & vbcrlf & "Number of active connections: " & colitems.count & vbcrlf
end if

for each objitem in colitems
xx= "ActiveTime : " & objItem.ActiveTime & vbcrlf
xx=xx & "Caption : " & objItem.Caption & vbcrlf
xx=xx & "ComputerName : " & objItem.ComputerName & vbcrlf
xx=xx & "ConnectionID : " & objItem.ConnectionID & vbcrlf
xx=xx & "Description : " & objItem.Description & vbcrlf
xx=xx & "InstallDate : " & objItem.InstallDate & vbcrlf
xx=xx & "Name : " & objItem.Name & vbcrlf
xx=xx & "NumberOfFiles: " & objItem.NumberOfFiles & vbcrlf
xx=xx & "NumberOfUsers: " & objItem.NumberOfUsers & vbcrlf
xx=xx & "ShareName : " & objItem.ShareName & vbcrlf
xx=xx & "Status : " & objItem.Status & vbcrlf
xx=xx & "UserName : " & objItem.UserName & vbcrlf
select case uselog
case true
objlogfile.writeline(xx & vbcrlf)
case false
wscript.echo xx & vbcrlf
end select
next

if uselog=vbtrue then
objlogfile.close
else
wscript.echo "------ " & f.name & " End " & date & " " & time() &" -----"
end if

wscript.quit


Then the 'log' file creation:

'****************************************************************************************
' Script : CreateLogFile.vbs
' Date : Dec, 28th 2005
' Description: creates a text file with .Log extension.
' Usage:
' Cscript CreateLogFile.vbs /F:"filename.ext" /P:"full path name"
' Parms:
' /F - mandatory - log file name. The .log extension will be added at the
' end
' /P - optional - log file path without final "\". If this parm is not
' specified, the running path of this script will be used.
' Version : 1.0
'****************************************************************************************

CONST ForReading = 1, ForWriting = 2, ForAppending = 8

ArgNum=wscript.arguments.count
set namedarguments=WScript.Arguments.Named
if namedarguments.exists("F") then
Set objFSO = CreateObject("Scripting.FileSystemObject")
logfilename=namedarguments.item("f") & ".log"
if namedarguments.exists("P") then
logfilepath=namedarguments.item("p") & "\"
else
Set f = objfso.GetFile(wscript.scriptname)
logfilepath=f.parentfolder & "\"
end if
if not objfso.fileexists(logfilepath & logfilename) then
set flog=objfso.opentextfile(logfilepath & logfilename, forwriting, vbtrue)
flog.writeline(logfilename & " created " & date() & " " & time ())
flog.close
end if
end if

wscript.quit


I scheduled it to run during lunchtime, when admins do their job. You may use

C:\WINDOWS\system32\wscript.exe //B c:\documenti\scripts\CheckActiveConnections.vbs /L


Feedback welcome.

Ciao
 
 
Post #: 1
 
 RE: check connections to your shared folders - 1/17/2006 7:09:18 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Reposted with formatting:

      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to red_phender)
 
 
Post #: 2
 
 RE: check connections to your shared folders - 1/17/2006 7:38:01 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I would suggest making the log creation a sub in the main script rather than shelling out to another script.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: check connections to your shared folders - 1/17/2006 9:12:52 PM   
  red_phender


Posts: 9
Score: 0
Joined: 1/17/2006
Status: offline
quote:

ORIGINAL: ebgreen

I would suggest making the log creation a sub in the main script rather than shelling out to another script.



Yes, right. I made it that way as exercise.
I see you've reposted with formatting. May I do it by myself (did I miss any instruction on how to?), if yes how?

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: check connections to your shared folders - 1/18/2006 2:21:04 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
You just need to use the code tags which are [ c o d e] and [ / c o d e ] only without the spaces.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to red_phender)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> check connections to your shared folders Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts