473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to use WMI to get remote computer's directory size?

How can I use WMI with VB.NET to get a remote computers directory size?
How can I use a unc_path within WMI? Previously I used FileInfo and
DirectoryInfo but this method takes too long because some of the
directories are over 30GB's in size. Please help!

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
4 12517
Von:
Here is a peice of code. The parameter to pass is the servername (hostname)
and will get you basic stat need for storage management. It is in C# and you
can easily convert it to VB.Net in minutes.

private void CalculateFreeUsed(string srvname)

{
try

{

// Connection credentials to the remote computer -

// not needed if the logged in account has access

ConnectionOptions oConn = new ConnectionOptions();

// oConn.Username = "JohnDoe";

// oConn.Password = "JohnsPass";

string strNameSpace = @"\\";

if (srvname != "")

strNameSpace += srvname;

else

strNameSpace += ".";

strNameSpace += @"\root\cimv2";
System.Management.ManagementScope oMs = new
System.Management.ManagementScope(strNameSpace, oConn);

//get Fixed disk stats

System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select FreeSpace,Size,Name from
Win32_LogicalDisk where DriveType=3");

//Execute the query

ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
//Get the results

ManagementObjectCollection oReturnCollection = oSearcher.Get();

//loop through found drives and write out info

foreach( ManagementObject oReturn in oReturnCollection )

{

// Disk name

//Console.WriteLine("Name : " + oReturn["Name"].ToString());
// Free Space in bytes

strFreespace = oReturn["FreeSpace"].ToString();

D_Freespace = D_Freespace + System.Convert.ToDouble(strFreespace);

// Size in bytes

strTotalspace = oReturn["Size"].ToString();

D_Totalspace = D_Totalspace + System.Convert.ToDouble(strTotalspace);
}

}

catch

{

MessageBox.Show("Failed to obtain Server Information. The node you are
trying to scan can be a Filer or a node which you don't have administrative
priviledges. Please use the UNC convention to scan the shared folder in the
server","Server Error",MessageBoxButtons.OK, MessageBoxIcon.Error) ;

}

}

Hope this helps

Yonas

"Von Thep via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:1c******************************@DotNetMonste r.com...
How can I use WMI with VB.NET to get a remote computers directory size?
How can I use a unc_path within WMI? Previously I used FileInfo and
DirectoryInfo but this method takes too long because some of the
directories are over 30GB's in size. Please help!

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #2
Thanks for the tip Yonas. One more question do I need an Assembly
reference or a namespace I need to use?

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #3
yes, the following reference:

System.Management

Yonas

"Von Thep via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:1d******************************@DotNetMonste r.com...
Thanks for the tip Yonas. One more question do I need an Assembly
reference or a namespace I need to use?

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #4
I feel like I'm so close but still no results. I'm getting an invalid
parameter error.

Here's what I have:

[code]
Imports System
Imports System.Management

Module Module1

Sub Main()
CalculateFreeUsed("\\MyServer\ShareA")
End Sub
Sub CalculateFreeUsed(ByVal srvname As String)

Try

Dim oConn As ConnectionOptions = New ConnectionOptions

Dim strNameSpace As String

If srvname <> "" Then
strNameSpace += srvname
Else
strNameSpace += "."
strNameSpace += "\root\cimv2"
End If

Dim oMs As New ManagementScope(strNameSpace, oConn)
Dim oQuery As New ObjectQuery("select FreeSpace,Size,Name from
Win32_LogicalDisk where DriveType=3")

'Execute the query
'Get the results
Dim oReturnCollection As ManagementObjectCollection
Dim search As New ManagementObjectSearcher(oMs, oQuery)
' Display each entry for Win32_processor

Dim info As ManagementObject

For Each info In search.Get()

Dim strFreespace As String = info("FreeSpace").ToString()
Dim D_Freespace As Integer = D_Freespace + System.Convert.ToDouble
(strFreespace)
Console.WriteLine(D_Freespace & vbCrLf)
'Size in bytes
Dim strTotalspace As String = info("Size").ToString()
Dim D_Totalspace As Integer = D_Totalspace + System.Convert.ToDouble
(strTotalspace)
Next
Catch ex As Exception
Console.WriteLine(ex.Message)

End Try

End Sub

End Module

[\code]

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lamont | last post by:
VB.NET Can anyone tell me how I can get the Drive Space information from a remote computer on the same domain and physical network? Primarily I need the Total disk space and space used or free...
6
by: deko | last post by:
In a multi-user environment, I have a table that stores hyperlinks to documents that are stored on the machine that hosts the mdb database. The table entry looks like this: ...
1
by: Yaniv M | last post by:
Hi, How can I get information of specific file in remote computer? I want to get file's status in other computer, this file belongs to shared directory, I want to get the file size, existanse of...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
1
by: Orgil | last post by:
Hi all, I'm working on a ASP web site. The site has some pages for uploading files to its server. I'm working on my computer as a local server. When pages of the web become ready, I copy the...
0
by: SayamiSuchi | last post by:
Hi, I have made one web application using Asp dot net 2005 and sql server 2005.The sql server i am connecting is the remote sql server..When i run my application in my computer and in LAN, it...
2
by: SayamiSuchi | last post by:
-------------------------------------------------------------------------------- Hi, I have made one web application using Asp dot net 2005 and sql server 2005.The sql server i am connecting is...
6
by: SayamiSuchi | last post by:
i got some problems in running my application from the server...I have used ASP DOT NET 2005 and SQL SERVER 2005.Actually the web application i had made is run in my pc and our LAN.We are using the...
7
by: luker | last post by:
Hello Experts, I am writing an application for a device running windows xp embedded. I want to code on my developer pc and deploy the running executable to the embedded device. - The two boxes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.