Auditing File Shares on Clients
Here is a script I wrote that will list out all the file and printer shares on all the machines in your domain. The script uses the RootDSE object to locate the root of your domain, and then connects to the WMI service on all your machines remotely, so you'll need to be logged in as a Domain Administrator for this script to work properly.
Output: The script will output a set of comma-separated headers that have been statically entered (Computer Name, Share Name, Share Type), and then will echo out a line for each printer or file share it encounters that contains the previously mentioned variables. The script will also detect if any computers were not able to be contacted, or had errors when attempting a connection to the remote WMI service and will echo those out at the end. I encourage you to run the script and review the output. Then, modify the script as necessary to suit your needs! I would be welcome to any suggestions you have as to how to improve this to assist your network administration and monitoring!
set pcsDown = CreateObject("Scripting.Dictionary") set pcsErr = CreateObject("Scripting.Dictionary") main()
function main() set rootdse = GetObject("LDAP://RootDSE") domain = rootdse.Get("defaultNamingContext") wscript.echo "Computer Name,Share Name,Share Type" searchDir(domain) printBadPCs() end function
'*************************** 'Declaration: function searchDir(ldappath) 'Purpose: Takes LDAP-formatted string as parameter. Performs an operation based on the directory object's class 'Return value: none '*************************** function searchDir(ldappath) set ou = GetObject("LDAP://" & ldappath)
for each dirObj in ou select case dirObj.class case "organizationalUnit" searchDir(dirObj.distinguishedName) case "container" searchDir(dirObj.distinguishedName) case "computer" if isAlive(dirObj.cn) then printShares(dirObj.cn) else pcsDown.Add dirObj.cn, "" end if end select next end function
'*************************** 'Declaration: printShares(pcname) 'Purpose: Prints the name of any type 0 (disk) or type 1 (print queue) shares on the machine 'Return value: nothing '*************************** function printShares(pcname) on error resume next numShares = 0 set shares = GetObject("winmgmts:\\" & pcname & "\root\cimv2:Win32_Share").Instances_ if Err.Number <> 0 then pcsErr.Add pcname, "" exit function end if
for each share in shares select case share.Type case 0 wscript.echo pcname & "," & share.Name & ",disk" numShares = numShares + 1 case 1 wscript.echo pcname & "," & share.Name & ",printer" numShares = numShares + 1 end select next ' if numShares <> 0 then wscript.echo "Total number of shares on " & pcname & ": " & numShares end function
'*************************** 'Declaration: function isAlive(pcname) 'Purpose: Sends ICMP packet to remote machine 'Return value: BOOL true if machine is alive, else BOOL false '*************************** function isAlive(pcname) isAlive = false set ping = GetObject("winmgmts:").ExecQuery("select * from Win32_PingStatus where Address = '" & pcname & "'")
for each png in ping if png.StatusCode = 0 then isAlive = true next end function
function printBadPCs() wscript.echo vbcrlf & "<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>" wscript.echo "The following computers could not be contacted" wscript.echo "<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>" for each pc in pcsDown wscript.echo pc next
wscript.echo vbcrlf & "<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>" wscript.echo "The following computers generated an error msg" wscript.echo "<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>" for each pc in pcsDown wscript.echo pc next end function
¶ 9:00 AM1 comments
Wednesday, December 06, 2006
Response to Digg Article Claiming to Free up Memory
So, a post on Digg.com recently came up where someone claimed that running rundll32.exe advapi32.dll,ProcessIdleTasks would in reality "clear up your system memory" and make your system run faster as a result! Of course, no claim like this should be believed these days without some factual basis, so I decided to do a little bit of research since I have a relatively good understanding of Windows as an o/s, and a novice understanding of programming.
As it turns out, there truly is a function in advapi32.dll called ProcessIdleTasks; This can be found using a tool from Nirsoft called DllExport Viewer. What is not correct, however, is the general understanding of what this function does. Simply doing a Google search for this function's name yielded quite a few results including articles and forum postings in which people claimed that this function freed up memory in Windows. Another interesting search result came from Microsoft itself, in the form of an article about benchmarking. In this article, it clearly states the following:
"The file placement optimization, which is done no more often than once every three days, is an example of a task that is carried out when the system is deemed to be idle. System Restore and other features of Windows XP also attempt to defer some work until the system is deemed to be idle. There are also some done-once-after-setup work items that also operate under the Idle Task Scheduling mechanisms.
All of these "idle tasks" are controllable by a system API in advapi32.dll, ProcessIdleTasks. The APIs sole purpose is to allow benchmarks a simple way to force any pending idle tasks to be executed immediately, without having to wait a lengthy period of time."
That, to me, seems like it has absolutely nothing to do with "memory optimization." It would seem that this function simply puts Windows XP into an idle state, enabling it to perform tasks that it wouldn't normally do while the computer is in use. Anyway, I hope this clears up some misunderstandings regarding the usage of this function.
¶ 6:08 AM10 comments
Friday, December 01, 2006
Sketching out the Lightbox
Here is the next video in which I draw out a quick sketch of the lightbox.