'************************************************************************** ' File: NetShare.vbs (WSH2 for VBscript and ADSI) ' Author: (c) M. Gallant 09/20/2000 ' ' Uses ADSI to enumerate network shares and properties of ' a win32 computer. ' No arguments version returns information for local machine. ' Command line (WScript or CScript) uses first argument as machine name. ' ' Based on information at: ' http://support.microsoft.com/support/kb/articles/Q234/2/34.asp ' http://msdn.microsoft.com/library/default.asp ' ?URL=/library/psdk/adsi/adsiscript_9lf0.htm '*************************************************************************** Option Explicit Dim machine, WshNet, myObj, args, winshares, ShareObj, info, host host = WScript.Application '------ Check for WSh2 if host <> "Windows Script Host" then WScript.Echo "This script requires Windows Script Host 2" WScript.Quit end if '------ Check for arguments set args = WScript.Arguments if args.Count>0 then machine = args(0) else set WshNet = WScript.CreateObject("WScript.Network") machine = WshNet.ComputerName End if on error resume next info = "*********** Information on \\" & machine & " **********" & vbCrLf & vbCrLf '---- Bind the remote computer's LanManServer to a IADsFileShare object. ' The IADsFileShare interface inherits from the basic IADs interface. Set winshares = GetObject("WinNT://" & machine & "/LANMANSERVER") ' Bind computer to object. if Err then HandleError() info = info & "------------- Shared Resources -------------" & vbCrLf info = info & "[Name] [File Path] " & vbCrLf '----- Try to get the shares For Each ShareObj in winshares info = info & ShareObj.Name & Space(5) if Err then HandleError() else info = info & shareObj.Path & vbCrLf ' try to get absolute local path of file share. if Err then HandleError() end if Next '----- Get the computer properties Set myObj = GetObject("WinNT://" & machine & ",computer") info = info & vbCrLf & "------------- Computer Information -------------" & vbCrLf info = info & "Name is " & myObj.Name & vbCrLf ' IADs basic properties info = info & "Class is " & myObj.Class & vbCrLf info = info & "GUID is " & myObj.GUID & vbCrLf info = info & "ADsPath is " & myObj.ADsPath & vbCrLf info = info & "Parent is " & myObj.Parent & vbCrLf info = info & "Schema is " & myObj.Schema & vbCrLf info = info & "ComputerID is " & myObj.ComputerID & vbCrLf ' Computer object properties info = info & "Site is " & myObj.Site & vbCrLf info = info & "Description is " & myObj.Description & vbCrLf info = info & "Location is " & myObj.Location & vbCrLf info = info & "Owner is " & myObj.Owner & vbCrLf info = info & "Div is " & myObj.Division & vbCrLf info = info & "Dept is " & myObj.Department & vbCrLf info = info & "OS is " & myObj.OperatingSystem & vbCrLf info = info & "Model is " & myObj.Model & vbCrLf info = info & "Processor is " & myObj.Processor & vbCrLf info = info & "MemorySize is " & myObj.MemorySize & vbCrLf info = info & "Storage Capacity is " & myObj.StorageCapacity & vbCrLf info = info & "NetAddresses is " & myObj.NetAddresses & vbCrLf WScript.Echo info & "-----------------------------------------------------------------" on error goto 0 Sub HandleError() If (Err.Number = 432 Or Err.Number = &H800401E4) then 'win95 gives 432; NT gives 01E4 info = info & " Missing class; (probably ADSI not supported)." WScript.Echo info WScript.Quit Elseif Err.Number = &H80070035 then ' No Err.Description is reported for this error! info = info & " The network path was not found." &vbCrLf info = info & "------------------------------------------------------------------ " WScript.Echo info WScript.Quit Elseif Err.Number = &H80070005 then info = info & "na" & vbCrLf ' If path of share if not available. Elseif Err.Number = 424 then ' Ignore spurious "Object required" VBS runtime error. Elseif Err.Number <> &H8000500D then ' Exclude errors: ADSI property not found in cache. info = info & Err.Description & vbCrLf End if End Sub '*************************** End *************************************