Drive space info on remote server in VB.NET?
Posted on 2004-09-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
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.