Hello - here's my problem - trying to set up a lil bit of code that checks win2k disk quota and warns user if they are approaching their disk space threshold.


here's the code - (cut down for simplicity - this version doesnt really do much but should work)

Dim vol, quotauser
Set vol = CreateObject("Microsoft.DiskQuota.1")
vol.Initialize "C:\", false
quotauser = vol.finduser("insert user name here")
if quotauser.quotaused >= quotauser.threshold then
msgbox("Warning - nearing disk space limit")
end if

ok - so - why won't this work? - on running the script (by double-clicking the .vbs icon on my desktop cos I aint running it over our net til I know it works safely) - I get the following error message from Windows Script Host

Line:4
Char:1
Error: Object doesn't support this property or method
Code: 800A01B6

weird - especially since I found the finduser method of the diskquotacontrol object right there on msdn site - so - anyone got any ideas?

Thanks


Paladine commented: Excellent - Intermediate to Advanced Knowledge Required! +36

Don't have the answer but here is some related script that may point you in the right direction.

Author: Jason Tanem 

Description: 

This script reads in the names of drives and sends an email warning via Outlook if finds that a drive is below 2.5 GB free. 
Script: 

'= This script reads in the names of drives =
'= <vDriveList> and sends an email warning via =
'= Outlook if finds that a drive is below 2.5 GB =
'= of free space. =
'= =
'= The text file <vDriveLlist> format should contain =
'= one drive entry per line as follows: =
'= =
'= C =
'= D =
'= \\server\resource name =
'==============

'Written by Jason Tanem

'------------Declarations-------
dim vFileSys, vShell, vLowIndicator, vDrv
dim vDrvFree, vOutlook, vMessage, vMailTo
dim vDriveList, vOpenText, vTextLine

vDriveList = "C:\Temp\Shares.txt"

'-------------Functions------

'Boolean for space above or below 2.5 GB

Function FreeSpaceStatus(drvPath)
     set vFileSys = CreateObject("Scripting.FileSystemObject")
     set vDrv = vFileSys.GetDrive(drvPath)
     vLowIndicator = "OK"

     If FormatNumber(((vDrv.FreeSpace/1024)/1024)/1024, 0) < 2.5 Then
          vLowIndicator = "Low"
     End If

     FreeSpaceStatus = vLowIndicator
End Function


'This function returns drive free space in GB
'-----------

Function FreeSpace(drvPath)
     Set vFileSYs = CreateObject("Scripting.FileSystemObject")
     Set vDrv = vFileSys.GetDrive(drvPath)
     vDrvFree = FormatNumber(((vDrv.FreeSpace/1024)/1024)/1024, 2) & " GB"
     FreeSpace = vDrvFree
End Function

'------------Main------
Set vFileSys = CreateObject("Scripting.FileSystemObject")
Set vOpenText = vFileSys.OpenTextFile(vDriveList)

Do While vOpenText.AtEndOfStream <> True
vTextLine = vOpenText.ReadLine

     If FreeSpaceStatus(vTextLine) = "Low" Then
          'Create and send the email by calling on Outlook via COM
                '----------------

          Set vOutlook = CreateObject("Outlook.Application")
          Set vMessage = vOutlook.CreateItem(0)

          With vMessage
          Set vMailTo = vMessage.Recipients.Add("jptanem@mapllc.com")
          vMailTo.Type = 1
               .Subject = "Low drive space on network resource"
               .Body = vTextLine & " is down to " & FreeSpace(vTextLine)
               .Importance = 2
               .Send
          End With
     End If
Loop

'Clean Up
'---

set vFileSys = Nothing
Set vShell = Nothing
Set vOpenText = Nothing
Set vOutlook = Nothing
Set vMessage = Nothing
WScript.Quit

Thanks Paladine - that helps me with another problem I wanted to sort out, but doesnt really help with interfacing the script to DiskQuota. I want ultimately to include this script in the users login script ( over 1000 users on this network) so they can be notified on login of their personal disk space status. any ideas?

QkSTechTrainee;

Sorry I don't have any other ideas at the moment, but I can post the website I got that script from, it may have something else that can help.

Problem is, I am at work and the site address is at home, (google was no help) so I will post back later on...k!?!

Thanks Paladine - all help gratefully received

set objDiskQuota=Createobject("Microsoft.Diskquota.1")
objDiskQuota.Initialize "D:\", True
objDiskQuota.LogQuotaThreshold =True
set objUser=objDiskQuota.FindUser("domain\" & "username")

QuotaLimit = objUser.QuotaLimit / 1048576
PercentageQuotaUsed = int(100*(objUser.QuotaUsed / objUser.QuotaLimit ))

The Above works fine on our webfarm for showing website quota's so should work fine for you as well.

Diskquota's are dodgy as hell btw I have enountered many exception errors while writing a perl version of the above plus we had problems with the finduser not finding the user till the 2nd attempt with no reason why.
Make sure you test the user exists then loop the finduser part to get around this.

Hello - here's my problem - trying to set up a lil bit of code that checks win2k disk quota and warns user if they are approaching their disk space threshold.


here's the code - (cut down for simplicity - this version doesnt really do much but should work)

Dim vol, quotauser
Set vol = CreateObject("Microsoft.DiskQuota.1")
vol.Initialize "C:\", false
quotauser = vol.finduser("insert user name here")
if quotauser.quotaused >= quotauser.threshold then
msgbox("Warning - nearing disk space limit")
end if

ok - so - why won't this work? - on running the script (by double-clicking the .vbs icon on my desktop cos I aint running it over our net til I know it works safely) - I get the following error message from Windows Script Host

Line:4
Char:1
Error: Object doesn't support this property or method
Code: 800A01B6

weird - especially since I found the finduser method of the diskquotacontrol object right there on msdn site - so - anyone got any ideas?

Thanks

On the 4th line it reads:
quotauser = vol.finduser("insert user name here")

It should read:

set quotauser = vol.finduser("insert user name here")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.