ScoobyNet.com - Subaru Enthusiast Forum

ScoobyNet.com - Subaru Enthusiast Forum (https://www.scoobynet.com/)
-   Non Scooby Related (https://www.scoobynet.com/non-scooby-related-4/)
-   -   Anybody done any programming using WMI?? (https://www.scoobynet.com/non-scooby-related-4/56246-anybody-done-any-programming-using-wmi.html)

David_Wallis 26 November 2001 06:43 PM

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.

kryten 26 November 2001 07:28 PM

normal thing is that the user that is logged on to the local machine, doesn't have sufficient privalidges on the remote machine...

David_Wallis 26 November 2001 08:13 PM

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]

David_Wallis 27 November 2001 01:31 PM

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..



All times are GMT +1. The time now is 07:09 PM.


© 2024 MH Sub I, LLC dba Internet Brands