473,713 Members | 2,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12559
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 CalculateFreeUs ed(string srvname)

{
try

{

// Connection credentials to the remote computer -

// not needed if the logged in account has access

ConnectionOptio ns oConn = new ConnectionOptio ns();

// oConn.Username = "JohnDoe";

// oConn.Password = "JohnsPass" ;

string strNameSpace = @"\\";

if (srvname != "")

strNameSpace += srvname;

else

strNameSpace += ".";

strNameSpace += @"\root\cimv 2";
System.Manageme nt.ManagementSc ope oMs = new
System.Manageme nt.ManagementSc ope(strNameSpac e, oConn);

//get Fixed disk stats

System.Manageme nt.ObjectQuery oQuery = new
System.Manageme nt.ObjectQuery( "select FreeSpace,Size, Name from
Win32_LogicalDi sk where DriveType=3");

//Execute the query

ManagementObjec tSearcher oSearcher = new
ManagementObjec tSearcher(oMs,o Query);
//Get the results

ManagementObjec tCollection oReturnCollecti on = oSearcher.Get() ;

//loop through found drives and write out info

foreach( ManagementObjec t oReturn in oReturnCollecti on )

{

// Disk name

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

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

D_Freespace = D_Freespace + System.Convert. ToDouble(strFre espace);

// Size in bytes

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

D_Totalspace = D_Totalspace + System.Convert. ToDouble(strTot alspace);
}

}

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",MessageB oxButtons.OK, MessageBoxIcon. Error) ;

}

}

Hope this helps

Yonas

"Von Thep via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message
news:1c******** *************** *******@DotNetM onster.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.Manageme nt

Yonas

"Von Thep via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message
news:1d******** *************** *******@DotNetM onster.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.Manageme nt

Module Module1

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

Try

Dim oConn As ConnectionOptio ns = New ConnectionOptio ns

Dim strNameSpace As String

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

Dim oMs As New ManagementScope (strNameSpace, oConn)
Dim oQuery As New ObjectQuery("se lect FreeSpace,Size, Name from
Win32_LogicalDi sk where DriveType=3")

'Execute the query
'Get the results
Dim oReturnCollecti on As ManagementObjec tCollection
Dim search As New ManagementObjec tSearcher(oMs, oQuery)
' Display each entry for Win32_processor

Dim info As ManagementObjec t

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.WriteLi ne(D_Freespace & vbCrLf)
'Size in bytes
Dim strTotalspace As String = info("Size").To String()
Dim D_Totalspace As Integer = D_Totalspace + System.Convert. ToDouble
(strTotalspace)
Next
Catch ex As Exception
Console.WriteLi ne(ex.Message)

End Try

End Sub

End Module

[\code]

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

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

Similar topics

3
826
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 (or both). -- Lamont - OKC Developer
6
5873
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: ProductDescription.htm#file:\\DBHOST\C$\Documents and Settings\Administrator\My Documents\Products\Documents\ProductDescription.htm Having the hyperlink in this format allows the document to be opened by anyone on the local area network.
1
3789
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 the file ..., When tring to acsess to file or get status it fails, Should I do login to this computer? if so, how can I do it? code examples are attached. Thanks
15
7081
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 every second. I remote desktop to the computer hosting this application and run the application. It starts up and displays the counter incrementing every second. If I disconnect the network cable between the two computers for 10 seconds and...
1
2023
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 pages to a remote directory of a remote web server . When I upload files to the local server, any file is completely uploaded. But when files are uploaded to a remote server, the size of each file is 20 bytes less than the original file size and...
0
1233
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 worked without any error..I run it after publishing it and even making virtual directory..It worked fairly...But when i upload the application to the remote machine.e i uploaded my application(published application including virtual directory) and try to...
2
1874
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 worked without any error..I run it after publishing it and even making virtual directory..It worked fairly...But when i upload the application to the remote machine.e i...
6
1499
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 remote sql server and it's running quiet well.I dont have problem in the database..It's ok..Now i want to put my application in the remote server..i dont have much permission of the remote server..I was asked to put my application in that server...
7
4163
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 are linked directly by a network cable. - Both are in the same subnetwork and are able to ping each other. - Each box is sharing a directory. - Each box has a remotely shared directory opened in an explorer window. - The development pc is in...
0
8794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8701
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9300
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9166
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9007
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3154
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.