#246747 - 17/01/2005 20:02
Can anyone help me with some wmi/vb programming?
|
new poster
Registered: 03/01/2005
Posts: 11
|
I need a way to find out all of the free space of the local hard drives on our Windows 2003 network/domain. There's about 500 computers and it would take too long to go to each one. I was told that it can be done via wmi or vb script, but I don't know how to do that. If there are any programmers on this forum that can help, I'd really appreciate it.
|
Top
|
|
|
|
#246748 - 17/01/2005 20:10
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Let's see.
On first blush, here's how I'd do it...
1. Make sure the program is run with full Domain Administrator privileges or this won't work.
2. Make sure the computers in question are all participating in the domain. (i.e., an admin can connect to their default shares.)
3. Make sure all the computers in question are running Windows NT, Windows 2000, Windows XP, or Windows 2003.
4. Make sure all the computers in question are turned on.
Then the program code would do the following:
1. Obtain the list of servers in the domain. Hm. I don't actually know how to do that off the top of my head. But perhaps you don't need to do that, maybe you have a list that's already created by hand. Or you can make that list yourself by redirecting the output of the NET command or something.
2. For each computername, map a drive (let's say "Z:") to \\computername\C$.
3. Get the free space on Z:.
4. Next computer.
I'm pretty sure all of that can be done pretty easily in VB.
|
Top
|
|
|
|
#246749 - 17/01/2005 20:17
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Yeah, the command line of :
net view /domain:domainname
gets you an ASCII list of the currently connected domain-participating PCs. So if you only have to run this thing once, no sense in writing code to deal with that. Just get the list and put it in the code.
|
Top
|
|
|
|
#246750 - 17/01/2005 20:32
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Hm. You might not need to map a drive. You might be able to show free space directly on the network share information. Lemme experiment a bit.
|
Top
|
|
|
|
#246751 - 17/01/2005 20:34
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Yup, this code works for me:
Code:
Private Sub Form_Load()
Form1.AutoRedraw = True 'Required for you to see the text on the form.
Form1.Print ShowAvailableSpace("c:")
Form1.Print ShowAvailableSpace("p:")
Form1.Print ShowAvailableSpace("\\ks1572ln01\c$")
Form1.Print ShowAvailableSpace("\\ks1572ln01\d$")
Form1.Print ShowAvailableSpace("\\ks1572ln01\public")
End Sub
Public Function ShowAvailableSpace(drvPath) As String
Dim fs, d, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & d.VolumeName & vbCrLf
s = s & "Available Space: " & FormatNumber(d.AvailableSpace / 1024, 0)
s = s & " Kbytes"
ShowAvailableSpace = s
End Function
In the example above, C is my local hard drive, P is mapped to \\ks1572ln01\public, and D$ is the drive on which public resides. The results of the queries, to p, public, and D$ all returned the same values. C and C$ gave the expected values.
So no need to map drives. You only need to get the list of computers and hard code those in quick and dirty. And the NET command will do that for you as I illustrated above.
|
Top
|
|
|
|
#246752 - 17/01/2005 21:00
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
pooh-bah
Registered: 25/08/2000
Posts: 2413
Loc: NH USA
|
First, a disclaimer: I don't know windows Scripting. But...I do have the M$ Windows 2000 Scripting guide. From it I got the following: Quote:
Retrieving System Information Computer Assets, Listing 8.1
Description Retrieves information similar to that returned by the System Information utility.
Script Code
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colSettings = objWMIService.ExecQuery _ ("SELECT * FROM Win32_OperatingSystem") For Each objOperatingSystem in colSettings Wscript.Echo "OS Name: " & objOperatingSystem.Name Wscript.Echo "Version: " & objOperatingSystem.Version Wscript.Echo "Service Pack: " & _ objOperatingSystem.ServicePackMajorVersion _ & "." & objOperatingSystem.ServicePackMinorVersion Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer Wscript.Echo "Windows Directory: " & _ objOperatingSystem.WindowsDirectory Wscript.Echo "Locale: " & objOperatingSystem.Locale Wscript.Echo "Available Physical Memory: " & _ objOperatingSystem.FreePhysicalMemory Wscript.Echo "Total Virtual Memory: " & _ objOperatingSystem.TotalVirtualMemorySize Wscript.Echo "Available Virtual Memory: " & _ objOperatingSystem.FreeVirtualMemory Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles Next Set colSettings = objWMIService.ExecQuery _ ("SELECT * FROM Win32_ComputerSystem") For Each objComputer in colSettings Wscript.Echo "System Name: " & objComputer.Name Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer Wscript.Echo "System Model: " & objComputer.Model Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone Wscript.Echo "Total Physical Memory: " & _ objComputer.TotalPhysicalMemory Next Set colSettings = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Processor") For Each objProcessor in colSettings Wscript.Echo "System Type: " & objProcessor.Architecture Wscript.Echo "Processor: " & objProcessor.Description Next Set colSettings = objWMIService.ExecQuery _ ("SELECT * FROM Win32_BIOS") For Each objBIOS in colSettings Wscript.Echo "BIOS Version: " & objBIOS.Version Next
This might get you started. It doesn't do HD Free Space, but it could serve as a framework for you to modify.
Used with this script (which reads computer names from a file):
Quote:
Const ForReading = 1 Set objDictionary = CreateObject("Scripting.Dictionary") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("c:\scripts\servers.txt", ForReading) i = 0 Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline objDictionary.Add i, strNextLine i = i + 1 Loop For Each objItem in objDictionary StrComputer = objDictionary.Item(objItem) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2") Set colServices = objWMIService.ExecQuery _ ("SELECT * FROM Win32_Service") Wscript.Echo strComputer, colServices.Count Next
and this bit:
Quote:
Enumerating Logical Disk Drive Properties Disks and File Systems, Listing 10.3
Description Displays property values for all the logical disk drives on a computer.
Script Code
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("SELECT * FROM Win32_LogicalDisk") For each objDisk in colDisks Wscript.Echo "Compressed: " & objDisk.Compressed Wscript.Echo "Description: " & objDisk.Description Wscript.Echo "Device ID: " & objDisk.DeviceID Wscript.Echo "Drive Type: " & objDisk.DriveType Wscript.Echo "File System: " & objDisk.FileSystem Wscript.Echo "Free Space: " & objDisk.FreeSpace Wscript.Echo "Media Type: " & objDisk.MediaType Wscript.Echo "Name: " & objDisk.Name Wscript.Echo "Size: " & objDisk.Size Wscript.Echo "Supports FileBased Compression: " & _ objDisk.SupportsFileBasedCompression Wscript.Echo "System Name: " & objDisk.SystemName Wscript.Echo "Volume Name: " & objDisk.VolumeName Wscript.Echo "Volume Serial Number: " & _ objDisk.VolumeSerialNumber Next
or more tersely, this:
Quote:
Enumerating Free Disk Space Disks and File Systems, Listing 10.6
Description Enumerates the amount of free disk space for all the hard disks on a computer.
Script Code
Const HARD_DISK = 3 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " _ & HARD_DISK & "") For Each objDisk in colDisks Wscript.Echo "Device ID: " & objDisk.DeviceID Wscript.Echo "Free Disk Space: " & objDisk.FreeSpace Next
You might have the start of something.
-Zeke
_________________________
WWFSMD?
|
Top
|
|
|
|
#246753 - 17/01/2005 21:02
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
pooh-bah
Registered: 25/08/2000
Posts: 2413
Loc: NH USA
|
Oh yeah, forgot to mention: Get this book.-Zeke
_________________________
WWFSMD?
|
Top
|
|
|
|
#246754 - 17/01/2005 21:12
Re: Can anyone help me with some wmi/vb programming?
[Re: Ezekiel]
|
new poster
Registered: 03/01/2005
Posts: 11
|
Wow, I got some fast replies on this board. Thanks so much for the input. I'm going to try to test the above code out. I posted this question yesterday on a .NET board, and no one has even replied there yet.
|
Top
|
|
|
|
#246755 - 17/01/2005 21:20
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
pooh-bah
Registered: 25/08/2000
Posts: 2413
Loc: NH USA
|
Try the attached .vbs file, and replace orange with one of your computer names.
Run it inside a windows scripting host if you don't want a ton of little pop-up windows.
-Zeke
Attachments
246025-driveinfo.vbs (207 downloads)
_________________________
WWFSMD?
|
Top
|
|
|
|
#246756 - 18/01/2005 00:12
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
carpal tunnel
Registered: 08/07/1999
Posts: 5549
Loc: Ajijic, Mexico
|
Wow, I got some fast replies on this board.Oh, I get it -- you're being sarcastic. Why, it took Tony a full 24 minutes to come up with the solution. I tell you, this bbs just ain't what it used to be... tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"
|
Top
|
|
|
|
#246757 - 18/01/2005 00:21
Re: Can anyone help me with some wmi/vb programming?
[Re: Ezekiel]
|
new poster
Registered: 03/01/2005
Posts: 11
|
thanks for the file, is there a way to get this to save to a text file instead of little pop up boxes?
|
Top
|
|
|
|
#246758 - 18/01/2005 00:51
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
pooh-bah
Registered: 15/01/2002
Posts: 1866
Loc: Austin
|
|
Top
|
|
|
|
#246759 - 18/01/2005 01:31
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
veteran
Registered: 19/06/2000
Posts: 1495
Loc: US: CA
|
First time doing VBS, but this should write a file called "driveinfo.txt" to the directory you run the script from.
Quote:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFH = oFSO.CreateTextFile("driveinfo.txt",True)
For Each objItem in colItems
oFH.Write "SystemName: " & objItem.SystemName & vbCrLf
oFH.Write "VolumeName: " & objItem.VolumeName & vbCrLf
oFH.Write "VolumeSerialNumber: " & objItem.VolumeSerialNumber & vbCrLf
oFH.Write "InstallDate: " & objItem.InstallDate & vbCrLf
oFH.Write "Description: " & objItem.Description & vbCrLf
oFH.Write "DriveType: " & objItem.DriveType & vbCrLf
oFH.Write "MediaType: " & objItem.MediaType & vbCrLf
oFH.Write "FileSystem: " & objItem.FileSystem & vbCrLf
oFH.Write "Status: " & objItem.Status & vbCrLf
oFH.Write "StatusInfo: " & objItem.StatusInfo & vbCrLf
oFH.Write "DeviceID: " & objItem.DeviceID & vbCrLf
oFH.Write "Name: " & objItem.Name & vbCrLf
oFH.Write "FreeSpace: " & objItem.FreeSpace & vbCrLf
oFH.Write "-------------------------------------------------------------" & vbCrLf & vbCrLf
Next
oFH.Close
At least it gets you started...
_________________________
Donato MkII/080000565 MkIIa/010101253 ricin.us
|
Top
|
|
|
|
#246760 - 18/01/2005 11:19
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
pooh-bah
Registered: 25/08/2000
Posts: 2413
Loc: NH USA
|
...see my disclaimer above. I can't help you further except to point to the M$ Scriptomatic tool info pages over at technet.
Edit: Scriptomatic 2 - much more flexible, outputs to VBS, Perl, JScript, Python as well as several file formats.
-Zeke
Edited by Ezekiel (18/01/2005 11:51)
_________________________
WWFSMD?
|
Top
|
|
|
|
#246761 - 31/01/2005 18:02
Re: Can anyone help me with some wmi/vb programming?
[Re: Ezekiel]
|
new poster
Registered: 03/01/2005
Posts: 11
|
Hey guys, I'm 99% there. I was able to get all the computers on the domain into a text file. I am able to get the program to read from the file line by line and get the HD info I want. The only problem is that the outputed textfile gets written over each time a new computer is scanned, instead of adding to the text file. Here's what I have....
***************************************************** Set fso = CreateObject("Scripting.FileSystemObject") Set textStreamObject = fso.OpenTextFile("c:\allcompsindomain.txt", 1, false, 0)
Do While Not textStreamObject.AtEndOfStream thisComputer = textStreamObject.readline
On Error Resume Next strComputer = thisComputer Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48) Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFH = oFSO.CreateTextFile("driveinfo.txt",True)
For Each objItem in colItems oFH.Write "SystemName: " & objItem.SystemName & vbCrLf oFH.Write "VolumeName: " & objItem.VolumeName & vbCrLf oFH.Write "VolumeSerialNumber: " & objItem.VolumeSerialNumber & vbCrLf oFH.Write "InstallDate: " & objItem.InstallDate & vbCrLf oFH.Write "Description: " & objItem.Description & vbCrLf oFH.Write "DriveType: " & objItem.DriveType & vbCrLf oFH.Write "MediaType: " & objItem.MediaType & vbCrLf oFH.Write "FileSystem: " & objItem.FileSystem & vbCrLf oFH.Write "Status: " & objItem.Status & vbCrLf oFH.Write "StatusInfo: " & objItem.StatusInfo & vbCrLf oFH.Write "DeviceID: " & objItem.DeviceID & vbCrLf oFH.Write "Name: " & objItem.Name & vbCrLf oFH.Write "FreeSpace: " & objItem.FreeSpace & vbCrLf oFH.Write "-------------------------------------------------------------" & vbCrLf & vbCrLf Next
oFH.Close
Loop *******************************************************
There is a text file in my c:\ drive called allcompsindomain.txt It successfully creates the driveinfo.txt file. Just need it to add info to the file instead of overwrite. Can anyone help?
thanks
|
Top
|
|
|
|
#246762 - 31/01/2005 18:09
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
veteran
Registered: 19/06/2000
Posts: 1495
Loc: US: CA
|
Change: Quote: Set oFH = oFSO.CreateTextFile("driveinfo.txt",True)
To:
Quote: Set oFH = oFSO.CreateTextFile("driveinfo.txt", 8, True)
_________________________
Donato MkII/080000565 MkIIa/010101253 ricin.us
|
Top
|
|
|
|
#246763 - 31/01/2005 19:00
Re: Can anyone help me with some wmi/vb programming?
[Re: ricin]
|
new poster
Registered: 03/01/2005
Posts: 11
|
Thanks for helping, I just tried that, and it doesn't seem work. It's only showing 1 computer's info in the text file.
|
Top
|
|
|
|
#246764 - 31/01/2005 19:06
Re: Can anyone help me with some wmi/vb programming?
[Re: dtwizzle]
|
veteran
Registered: 19/06/2000
Posts: 1495
Loc: US: CA
|
Oops. I meant this: Quote: Set oFH = oFSO.OpenTextFile("driveinfo.txt", 8, True)
_________________________
Donato MkII/080000565 MkIIa/010101253 ricin.us
|
Top
|
|
|
|
#246765 - 24/02/2005 22:52
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Quote: Yeah, the command line of :
net view /domain:domainname
gets you an ASCII list of the currently connected domain-participating PCs.
Anyone know the unix-equivalent of this?
How would you query the DNS server to list the names of the active PCs on its local subnet?
|
Top
|
|
|
|
#246766 - 24/02/2005 22:59
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
pooh-bah
Registered: 12/02/2002
Posts: 2298
Loc: Berkeley, California
|
smbstatus? Unless you "own" the dhcp sever, there's no real way of doing it.
(we don't need no stinkin' workgroups is the usual feeling, i believe)
matthew
|
Top
|
|
|
|
#246767 - 24/02/2005 23:08
Re: Can anyone help me with some wmi/vb programming?
[Re: matthew_k]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
|
Top
|
|
|
|
#246768 - 24/02/2005 23:47
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
addict
Registered: 14/11/2000
Posts: 474
Loc: The Hague, the Netherlands
|
Quote:
How would you query the DNS server to list the names of the active PCs on its local subnet?
host -t axfr dnsdomain dnsserver or dig @dnsserver dnsdomain axfr
The DNS server must allow zone transfers to your IP address for this to succeed. If your default DNS server is auhoritative for the domain, you can leave out the dnsserver arguments.
Pim
|
Top
|
|
|
|
#246769 - 25/02/2005 02:07
Re: Can anyone help me with some wmi/vb programming?
[Re: pim]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Ooo, even better. Thanks!
|
Top
|
|
|
|
#246770 - 25/02/2005 02:32
Re: Can anyone help me with some wmi/vb programming?
[Re: tfabris]
|
pooh-bah
Registered: 12/02/2002
Posts: 2298
Loc: Berkeley, California
|
What are you trying to accomplish exactly? The DNS server will give you all the hosts registered in the domain. It won't tell you which are active and which aren't. It's not one-to-one, and being there doesn't imply existance.
Smbstatus will give you all(?) the computers talking SMB, the majority of which are likely to be windows hosts.
The DHCP server would theoretically give you the list of all DHCP leases, but wouldn't give you any of the computers configured with static IPs.
And pinging everything in your subnet would give you a decent list execept that everyone's decided that they have to make their computers unpingable.
You probably knew most of this, just thought I'd explain a bit more...
Matthew
|
Top
|
|
|
|
#246771 - 25/02/2005 13:47
Re: Can anyone help me with some wmi/vb programming?
[Re: pim]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
If that works, it just gives the mappings in that zone, and the zone does not necessarily have any relationship to network addressing. That is, it'll give you all of yahoo.com, but the hosts in yahoo.com might be 192.168.4.45 and 10.78.4.123. In addition, there may well be computers in those subnets that exist in DNS and aren't in yahoo.com. To extend the above example, there may be a computer at 192.168.4.46 whose FQDN is www.yimg.com.
_________________________
Bitt Faulk
|
Top
|
|
|
|
#246772 - 25/02/2005 14:28
Re: Can anyone help me with some wmi/vb programming?
[Re: matthew_k]
|
pooh-bah
Registered: 12/02/2002
Posts: 2298
Loc: Berkeley, California
|
Also, look into an ARP ping. It's probably your best bet of finding all the computers on your physical network that are also in your subnet.
Matthew
|
Top
|
|
|
|
|
|