Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Drive space info on remote server in VB.NET?

Posted on 2004-09-21
5
1,856 Views
Last Modified: 2012-06-21
After going through alot of MSDN and EE, I can't seem to find an answer to my problem.  I'm trying to write a VB.NET app that will check on various things on servers, and return all the information in an Excel spreadsheet.  I've got most of it working, but can't seem to figure out how to get the drive information from a remote computer.  I got it to check my local PC with the following code:

  Sub CheckDiskSpace(ByVal strServer As String)

    Dim fsoDrive As Scripting.FileSystemObject
    Dim drvDrives As Scripting.Drives
    Dim drvDrive As Scripting.Drive
    Dim FreeSpace, PercentUsed
    Dim Rindex, Cindex

    exlRow = exlRow + 2
    exlSheet.Range(exlRow & ":" & exlRow).Font.Bold = True
    exlSheet.Range(exlRow & ":" & exlRow).HorizontalAlignment = xlHAlignCenter
    exlSheet.Range("A" & exlRow).Value = "Drive"
    exlSheet.Range("B" & exlRow).Value = "Free Space"
    exlSheet.Range("C" & exlRow).Value = "% Available"

    fsoDrive = CreateObject("Scripting.FileSystemObject", strServer)
    drvDrives = fsoDrive.Drives
    lblStatus.Text = "Checking drives"

    For Each drvDrive In drvDrives
      ' If the drive is a hard disk, check space; skips CD-ROMs and other drive types
      If drvDrive.DriveType = Scripting.DriveTypeConst.Fixed Then
        exlRow = exlRow + 1
        exlSheet.Range("A" & exlRow).Value = drvDrive.DriveLetter & ":"
        exlSheet.Range("B" & exlRow).NumberFormat = "#,##0.00"
        exlSheet.Range("B" & exlRow).Value = drvDrive.AvailableSpace / 1024 / 1024
        exlSheet.Range("C" & exlRow).NumberFormat = "0.00%"
        exlSheet.Range("C" & exlRow).Value = drvDrive.AvailableSpace / drvDrive.TotalSize
      End If
    Next

  End Sub

It seems like it tries to check the remote computer (I've tried on both Win2K Pro and Server computers), but fails.  Can anyone fix this, or tell me a better way to go about doing the same thing?  Most of the VB objects I've found will let you manipulate files and folders, but I can't find anything to get drive information.
0
Comment
Question by:HatchIT
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
sj_hicks earned 50 total points
ID: 12109817
You can do it with WMI.  Check out the Win32_LogicalDisk class - it will give you lots of info including drive letter and free disk space.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12109822
Probably, I dont get it correctly.
Unless and untill we have full access to the network system and logged into it, we can just get the information of share, not the Drives?
Can we do it using windows?
0
 
LVL 7

Expert Comment

by:sj_hicks
ID: 12109861
You can run WMI queries against remote computers.  The account you are running the application to check disk space from needs to have access to the remote computer.  If it does, then you can query all WMI info and even run WMI methods to do groovy systems admin stuff.

If you are trying to get this info from a remote computer and you don't have the required access, any method will fail.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12110101
ohh i c
Interesting..
I looked into it and found this article.
this may be interesting for the author
http://www.publicjoe.f9.co.uk/csharp/articles/csh-wmi.html
0
 
LVL 1

Author Comment

by:HatchIT
ID: 12165543
Thanks for that, sj_hicks.  Now that I know where to look, I should be able to sort this out.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question