Recipe 4.24. Viewing SharesProblemYou want to view the list of shares on a server. SolutionUsing a graphical user interface
Using a command-line interfaceThe following command displays administrative and nonadministrative shares: > net share To view the list of shares on a remote server, use the Sysinternals psexec.exe utility to run the net share command against the server: > psexec \\<ServerName> -u <User> net share For example: > psexec \\srv01 -u administrator net share You can also view all of the nonadministrative shares on a remote server using this command: > net view \\<ServerName> Using VBScript' This code displays all of the shares on a system. ' ------ SCRIPT CONFIGURATION ------ strComputer = "." ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colShares = objWMI.InstancesOf("Win32_Share") for each objShare in colShares WScript.Echo objShare.Name WScript.Echo " Path: " & objShare.Path WScript.Echo " Allow Max: " & objShare.AllowMaximum WScript.Echo " Caption: " & objShare.Caption WScript.Echo " Max Allowed: " & objShare.MaximumAllowed WScript.Echo " Type: " & objShare.Type WScript.Echo next DiscussionThe Sysinternals Shareenum program is another tool that you can use for viewing shares. It lists the shared folders on all hosts in a particular domain. Depending on the number of hosts in the domain, it can take a while to complete. It is interesting to see the output and discover what types of shared folders users have created. You may even want to periodically check the security on these shared folders to ensure that users are following your documented policies for shared folder security. |