Notices
Non Scooby Related Anything Non-Scooby related

Anybody done any programming using WMI??

Thread Tools
 
Search this Thread
 
Old 26 November 2001, 06:43 PM
  #1  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Hi,

Has anybody done any programming using vbs and wmi???

I can query the local machine but if I try and do a remote machine it goes pear shaped... both machines are w2k. I think it may just be something simple that I have missed....

I am trying to connect to a remote machine and then depending on the disk type (fixed) return the size and space that is free..

would submit my code, but I am at home now and cant be bothered dialing in to work.

David.
Old 26 November 2001, 07:28 PM
  #2  
kryten
Scooby Regular
 
kryten's Avatar
 
Join Date: May 2000
Posts: 869
Likes: 0
Received 0 Likes on 0 Posts
Post

normal thing is that the user that is logged on to the local machine, doesn't have sufficient privalidges on the remote machine...
Old 26 November 2001, 08:13 PM
  #3  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

doh... was me being thick... forward slash instead of backslash etc..

following code now works (VBS)...

NetBiosName="David01"

Set FixedDiskS = GetObject("winmgmts:{impersonationLevel=impersonat e}!//" & NetBiosName).ExecQuery ("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")

For Each Disk in FixedDisks
WScript.Echo "Drive " & Disk.Name & " Has " & KB(Disk.Freespace) & " Free."
Next

Function KB(Bytes)
KB = FormatNumber(Bytes/1024, 0) & " KB"
end function


In case anybody is interested it is part of a script that will query our sms (SQL) database and return a list of windows NT 4 Servers on our network, It then connects to them using WMI and works out Total Disk Size, Available Space and Used DiskSpace and then will output this to an excel spreadsheet....

David

[Edited by David_Wallis - 11/26/2001 8:14:25 PM]
as Tabs dont show up...

[Edited by David_Wallis - 11/26/2001 8:15:23 PM]
Old 27 November 2001, 01:31 PM
  #4  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Right.. Now working...

Here is code to connect to SMS site Server and Query the All windows nt servers collection and then use wmi to query the fixed disks as to what size they are and how much space is used, free etc.. do what you like with the output if you wish to use it..

David


' Script for Returning Free Disk Space on Servers.
' David Wallis 28/11/2001
' Uses WBEM / WMI / SMS

Dim WBEMLocator, ServerConnect, FindColl, FindColls, Server, Servers, SMSServer, Sitecode

' Change following two lines to match your SMS ServerName and SiteCode
' You will neeed to install wmi if not on w2k.

SMSServer="ServerName"
SiteCode="LS1"

Server="All Windows NT Server Systems"

Set WBEMLocator = CreateObject("Wbemscripting.SWbemLocator")
Set ServerConnect = WBEMLocator.ConnectServer(SMSServer, "root\sms\site_"& SiteCode)

' Convert the collection names visible in the SMS console, to the internal SMS/WMI name (SMS_CM_RES_....)

Set FindColls = ServerConnect.ExecQuery("Select Name, MemberClassName FROM SMS_Collection Where Name='" & Server & "'")

For Each FindColl in FindColls
If FindColl.Name = Server Then
ServerColl = FindColl.MemberClassName
End If
Next

Set Servers = ServerConnect.ExecQuery("Select System.ResourceID, System.NetbiosName FROM SMS_R_System AS System INNER JOIN " & ServerColl & " AS Coll ON Coll.ResourceID = System.Resourceid")

For Each Server in Servers
On Error Resume Next

' Put in a Ping Routine to check to see if the machine is on.

Set FixedDisks = GetObject("winmgmts:{impersonationLevel=impersonat e}!//" & Server.NetBiosName).ExecQuery ("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")

For Each Disk in FixedDisks
Used = Disk.Size - Disk.FreeSpace
WScript.Echo Server.NetBiosName & " " & Disk.Name & " Size: " & KB(Disk.Size) & " Free Space: " & KB(Disk.Freespace) & " Used: " & KB(Used)

Next

Set FixedDisks = Nothing

Next


Function KB(Bytes)
KB = FormatNumber(Bytes/1024, 0) & " KB"
End Function


apollogies if the tabs dont format correctly..

Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Steve Breen
ScoobyNet General
87
05 August 2001 05:29 PM
ChristianR
Non Scooby Related
1
16 June 2001 09:36 PM
johnfelstead
ScoobyNet General
27
26 February 2001 05:48 PM
classicrs
Non Scooby Related
4
19 February 2001 12:08 AM
JamesH
Non Scooby Related
5
21 July 2000 11:26 PM



Quick Reply: Anybody done any programming using WMI??



All times are GMT +1. The time now is 04:01 PM.