Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check free space on share 1

Status
Not open for further replies.

Krystian81

Programmer
Sep 10, 2012
11
PL
I`m new in here so I`d like to pass greetings to everybody.

The question is how to check free space on share drive using VBS?
My share is not a win machine. It`s a Network Attached Storage which has got its own IP address, ( 2,5 TB )

regards Krystian
 
Map it as a drive first.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
this disk is not mapped peristantly.
So I can:
1. map it in VBS
2. Check free space ( dont know how )
3. Unmap it

sample code

Dim objShell, objNetwork, strDrive

Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objNetwork = CreateObject("Wscript.Network");

strDrive = "\\myShareDrive\"
objNetwork.MapNetworkDrive "X:", strDrive
 
Have a look at
Here's a quick example provided be Guy Thomas
Code:
' DriveType3.vbs
' Sample VBScript to discover the drive type with WMI
' Author Guy Thomas [URL unfurl="true"]http://computerperformance.co.uk/[/URL]
' Version 2.1 - July 2006 Correction by Olav Meijer
' -----------------------------------------------' 
Option Explicit
Dim objWMIService, objItem, colItems, strComputer
Dim strDriveType, strDiskSize, strDisk
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

For Each objItem in colItems
   Select Case objItem.DriveType
      Case 1 strDriveType = "Drive could not be determined."
      Case 2 strDriveType = "Removable Drive"
      Case 3 strDriveType = "Local hard disk."
      Case 4 strDriveType = "Network disk." 
      Case 5 strDriveType = "Compact disk (CD)" 
      Case 6 strDriveType = "RAM disk." 
      Case Else strDriveType = "Drive type Problem."
   End Select

   If objItem.DriveType =2 Then 
      strDiskSize = Int(objItem.Size / (1024^2)) & " Mega Bytes" 
   Else
      strDiskSize = Int(objItem.Size / (1024^3)) & " GB" 
   End If 

   strDisk = strDisk & vbCr & _
      "Drive Letter: " & objItem.Name & vbCr & _ 
      "Drive Type : " & strDriveType & vbCr & _
      "Disk Size : " & strDiskSize & vbCr & "Free Space : " & _
      Int(objItem.FreeSpace / (1024^3)) & " GB" & vbCr & _
      " ========================="
Next

Wscript.Echo strDisk

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
With CreateObject("Scripting.FileSystemObject")
MsgBox .GetDrive("\\mysharedrive\").AvailableSpace & " bytes"
End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top