Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code help please...gathering logical disk information.

Status
Not open for further replies.

Digitalcandy

IS-IT--Management
May 15, 2003
230
US
Below is the code I'm using;




strComputer = "Computer Name"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For each objDisk in colDisks
Wscript.Echo "Name: " & vbTab & objDisk.Name
Wscript.Echo "Description: " & vbTab & objDisk.Description
Next



This returns the information I need, (drive letter and Description), but it enumerates for a given computer. Is there a way to specify an IP range and have the information be created in a text file?


 
This will do what you ask, but it hangs if the machine is unavailable. If anyone knows how to put a time on the binding to the objWMIService please let me know.

Code:
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile ("DiskInfo.txt", ForAppending, True)

For octet = 100 To 110
strComputer = "192.168.1." & octet
On Error Resume Next	
	Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	
		Set colDisks = objWMIService.ExecQuery _
	    ("Select * from Win32_LogicalDisk")
		For each objDisk in colDisks    
		     Name = objDisk.Name     
		     objDescription = objDisk.Description        
		Next
		Report = Report & "**********************************************"& vbCrLf
		Report = Report & strComputer & vbCrLf
		Report = Report & "Name:"& vbTab & Name & vbCrLf
		Report = Report & "Description:"& vbTab & objDescription & vbCrLf
		ts.write Report
		Report = ""

Next
WScript.Echo "Done"
Set objWMIService = nothing
Set ts = nothing
Set fso = nothing

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi Mark,
I don't know a way to create a timeout period for binding the objWMIService, but I first do a ping to the machine (using WMI) to see if it is alive...

Code:
Function TestConnection(strComputer)
    'Description:    Pings the given address using WMI
    'Returns:    Boolean True or False if a connection was found or not
    'Attention!    This is supported from winxp/server2003 up
    Dim objPing, objStatus
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
    ExecQuery("select * from Win32_PingStatus where address = '"_
    & strComputer & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then TestConnection = False
        If objStatus.StatusCode = 0 Then TestConnection = True
    Next
    Set objPing = Nothing
End Function

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
i do like that as a basic litmus test, but unfortunatly it does not account for systems that may respond to a ping but the user may have no access to for the other queries.

Anybody else have any suggestions?



I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Thanks for the help guys. Also, is there a way to obtain the path of network drives?
 
Yep, try these:

Code:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
For Each objItem in colItems
	WScript.Echo "AccessMask: " & objItem.AccessMask
	WScript.Echo "Caption: " & objItem.Caption
	WScript.Echo "Comment: " & objItem.Comment
	WScript.Echo "ConnectionState: " & objItem.ConnectionState
	WScript.Echo "ConnectionType: " & objItem.ConnectionType
	WScript.Echo "Description: " & objItem.Description
	WScript.Echo "DisplayType: " & objItem.DisplayType
	WScript.Echo "InstallDate: " & objItem.InstallDate
	WScript.Echo "LocalName: " & objItem.LocalName
	WScript.Echo "Name: " & objItem.Name
	WScript.Echo "Persistent: " & objItem.Persistent
	WScript.Echo "ProviderName: " & objItem.ProviderName
	WScript.Echo "RemoteName: " & objItem.RemoteName
	WScript.Echo "RemotePath: " & objItem.RemotePath
	WScript.Echo "ResourceType: " & objItem.ResourceType
	WScript.Echo "Status: " & objItem.Status
	WScript.Echo "UserName: " & objItem.UserName
Next

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
I found the code that I would like to collect data on. It list the only network drive letters and respective path, but I don't know how to incorporate it into markdmac's code of specifiying an IP range and outputting to text file.




Set WshNetwork = WScript.CreateObject("WScript.Network")
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1
WScript.Echo clDrives.Item(i)
Next
 
K0b3:

I've modified your code to get the info I want, but it doesn't seem to do anything when I run it against a remote 2000/XP computer.




strComputer = "RemoteComputerName"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
For Each objItem in colItems
WScript.Echo "Name: " & objItem.Name
Next


 
check if the userid you are running the script with has administrator rights on the remote machine. This is a must to be able to read/change the settings...

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
Digitalcandy you need to change
strComputer = "RemoteComputerName" to have the computer anem you want to run it against.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top