Remote machine hard drive free space

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
how can i find out the hard drive free space of remote machine.

for eg: need to find out the C drive's free space in remote machine.

any idea how can we find out this... if you have anyidea how to find out this, please help me. i just checked in internet, but didnt get any help.
not getting any idea now...

thanks in advance
 
This may help you

Hi,
You may download WmiCodeCreator from this link http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en and you will get what you need. Sample code from wmicodecreator is given below.

VB.NET:
        Try
            Dim connection As New ConnectionOptions
            connection.Username = "userName"
            connection.Password = "passWord"
            connection.Authority = "ntlmdomain:DOMAIN"

            Dim scope As New ManagementScope( _
                "\\FullComputerName\root\CIMV2", connection)
            scope.Connect()

            Dim query As New ObjectQuery( _
                "SELECT * FROM Win32_LogicalDisk")

            Dim searcher As New ManagementObjectSearcher(scope, query)

            For Each queryObj As ManagementObject In searcher.Get()

                Console.WriteLine("-----------------------------------")
                Console.WriteLine("Win32_LogicalDisk instance")
                Console.WriteLine("-----------------------------------")
                Console.WriteLine("FreeSpace: {0}", queryObj("FreeSpace"))
            Next

            Close()
        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        Catch unauthorizedErr As System.UnauthorizedAccessException

            MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)
        End Try
 
i tried this code for checking the free space in C drive.
no error is comming. but not able to see the output. while i tried to display this in messagebox error is comming.
how can i display the output for us to see what's the free space...

Try
Dim connection As New ConnectionOptions
connection.Username = "userName"
connection.Password = "passWord"
connection.Authority = "ntlmdomain:DOMAIN"

Dim scope As New ManagementScope( _
"\\FullComputerName\root\CIMV2", connection)
scope.Connect()

Dim query As New ObjectQuery( _
"SELECT * FROM Win32_LogicalDisk Where Name='C:'")

Dim searcher As New ManagementObjectSearcher(scope, query)

For Each queryObj As ManagementObject In searcher.Get()

Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_LogicalDisk instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("FreeSpace: {0}", queryObj("FreeSpace"))
Next

Close()
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException

MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)
End Try

anyidea, please help me.
thanks in advance
 
but by using this code i can view my local machine's C drive free space and while giving remote name and pwd i can see that machine's free space. but i'm not able to see that.

i need to see what is the output for this line.

Console.WriteLine("FreeSpace: {0}", queryObj("FreeSpace"))

i'm not able to see the output. whether we can display this output like messagebox....

thanks in advance.
 
Yes, you can use messagebox to display the string.
 
heah its working....

Dim processHandle As UInt64 ' Integer
Dim freespace As Integer 'Decimal

Dim query As New ObjectQuery("SELECT * FROM Win32_LogicalDisk Where Name='C:'")
Dim searcher As New ManagementObjectSearcher(query)

For Each queryObj As ManagementObject In searcher.Get()
processHandle = queryObj("FreeSpace")
freespace = processHandle.ToString / 1073741824
messagebox.show(freespace)
Next

actually queryObj("FreeSpace") is providing a UInt64, and i tried to take the value to integer, that's why error came. so i change the integer to Uint64. now its working.

Thanks a lot for your help. really thanks...

and the value we were getting is in bytes, so to convert it to GB i divide the bytes with 1024 three times. and i'm getting the value.

but its a long decimal number i'm receiving. like 49.2345123455
any way i can display it only as 49.23 instead of 49.2345123455.....
if you know please let me know. sorry for disturbing you again.

Thanks in advance. and thanks for your help .....
 
freespace = Format(freespace, ".00")

this will display only two decimal numbers.
now its working. now its displaying as 49.23 Gb.

thanks for your help....
 
Back
Top