Login | |
|
 |
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
|
|
| |
|
|
|
 |
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?
|
|
| |
|
|
|
|
|