473,387 Members | 1,464 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.

Space available on remote computer

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
Nov 22 '05 #1
3 30487
Hi Lamont,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get disk information from a
remote computer. If there is any misunderstanding, please feel free to let
me know.

We can use WMI to get this information remotely. Here I found a code
snippet that can caculate the total free disk space available on a remote
machine. It is in C# and you can easily convert it to VB.NET. Also, you can
make some changes to it to meet your needs.

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) ;
}
}

Please check the following link for more information on this snippet.

http://groups.google.com/group/micro...es.vb/browse_f
rm/thread/8cfed7c8d264ded/ebaf526cf2817346?lnk=st&q=disk+information+remote+
computer+wmi&rnum=7&hl=zh-CN#ebaf526cf2817346

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #2
You are correct, and I think this will do the job.

Thank you.
--
Lamont - OKC Developer
"Kevin Yu [MSFT]" wrote:
Hi Lamont,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get disk information from a
remote computer. If there is any misunderstanding, please feel free to let
me know.

We can use WMI to get this information remotely. Here I found a code
snippet that can caculate the total free disk space available on a remote
machine. It is in C# and you can easily convert it to VB.NET. Also, you can
make some changes to it to meet your needs.

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) ;
}
}

Please check the following link for more information on this snippet.

http://groups.google.com/group/micro...es.vb/browse_f
rm/thread/8cfed7c8d264ded/ebaf526cf2817346?lnk=st&q=disk+information+remote+
computer+wmi&rnum=7&hl=zh-CN#ebaf526cf2817346

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #3
You're welcome, Lamont.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #4

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

Similar topics

0
by: Pieter Linden | last post by:
Okay, the basic plan: 1. Call EnumerateServers to return an array of all the computers on the network. available at: http://datafast.cjb.net/ 2. Resolve the HostNames into IP Addresses....
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...
1
by: Bhavya Shah | last post by:
Hello All, I am facing a serious problem while copying a file to a remote computer programmatically. What I want to do: I want to connect to a remote computer and copy a file to the remote...
1
by: Chidvilas | last post by:
// Get all processes running on the remote computer. Process remoteAll = Process.GetProcesses("XYZ"); when I am exectuing the above code, it is giving excetpion saying "Couldn't get process...
4
by: Von Thep via DotNetMonster.com | last post by:
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...
0
by: py | last post by:
I am trying to execute a batch script on a remote computer. The batch script looks like: @echo off start c:\python24\python.exe c:\a_script.py Here's the setup: Computer A (my computer),...
1
by: schaf | last post by:
Hi all! I'm still trying to start/stop a service on a remote computer. (I promiss that's the last new post because of this problem from my side) My situation: I've an application running under...
0
by: Zebadunc | last post by:
I have a vb.net form that lists the shared printers in from a remote computer in a checklist box giving the shareName as the value for the user to select. I want to use the print server name and...
5
by: Sin Jeong-hun | last post by:
I need to read some registry keys of a remote computer. The key will be any key users provide. (For example : HKEY_CURRENT_USER\SOFTWARE \MyGame) I found that there was a handy method called...
1
by: Miguel Pires | last post by:
Hi, Any one knows a way to get Hard Drive letters and free space (C: / D: ....) from a remote computer? I'm developing one application that needs to know if a second drive exist on that system...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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,...

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.