Jump to content

[Fixed] Script not working. File Quota check/reporting at Login.


Recommended Posts

Posted

Having a thick moment. This script isn't working as expected. Any clues?

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService. _
ExecQuery("Select * from Win32_MappedLogicalDisk")

  
For Each objDisk in colDisks
	if objDisk.Name = "Z:" Then
		If objDisk.FreeSpace = 0 Then
			'Out of Space
			MsgBox "You have no space left in your My Documents. Please delete any unneeded files.", vbCritical + vbOKOnly, "Disk Quota Error!"

		Else If objDisk.FreeSpace < (objDisk.Size / 100) * 90 Then
			'Less than 10% left!
			MsgBox "You have very little space left in your My Documents. Please delete any unneeded files.", vbExclamation + vbOKOnly, "Disk Quota Warning!"

		End If
Next

Posted (edited)

What is it doing wrong? You could ditch the for loop totally by adding the criteria into your query which may help

 

select * from Win32_MappedLogicalDisk where name = "Z:"

Then just check that there are results and access them directly

Edited by SYNACK
Posted

Ok still having problems. I stripped everything down to a more basic script to test.

 

	strComputer = "."

  	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  	Set objDisk = objWMIService. _
   	ExecQuery("Select * from Win32_MappedLogicalDisk where DeviceID = Z:") 

MsgBox "Free Space on " & objDisk.DeviceID & " " & Int(objDisk.FreeSpace / 1024 / 1024 ) & "Mb of " & Int(objDisk.Size / 1024 / 1024) & "Mb", vbInformation + vbOKOnly, "Disk Quota Information"

 

Yet I'm getting the error "Object does not support this property or method 'objDisk.Name'

" on line 7. Yet that's not the case according to the documentation.

 

Win32_MappedLogicalDisk Class (Windows)

Posted

i used

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

 

instead of

 

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

and it seemed to work for me

 

Box

Posted

does this work?

 

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService. _
ExecQuery("Select * from Win32_MappedLogicalDisk")

  
For Each objDisk in colDisks
	if objDisk.Name = "Z:" Then
		Wscript.Echo objDisk.FreeSpace 
					End iF
Next

 

it works on vista

 

BoX

Posted (edited)

just out of interest, how do you get your "My Documents" or any mapped drive to report what they are allowed to use and not the total capacity of the server/drive it is hosted on?

 

would it not give the same message to all users on the same server/drive?

 

BoX

 

Edit: i guess you use quotas

Edited by box_l
Posted

Ok, so back to my original script. All fixed and working! :)

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService. _

ExecQuery("Select * from Win32_MappedLogicalDisk")



For Each objDisk in colDisks

if objDisk.Name = "Z:" Then	

	If objDisk.FreeSpace = 0 Then

		'Out of Space

		MsgBox "You have no space left in your My Documents. Please delete any unneeded files.", vbCritical + vbOKOnly, "Disk Quota Error!"

		Else If objDisk.FreeSpace < (objDisk.Size / 100) * 90 Then

			'Less than 10% left!

			MsgBox "You have very little space left in your My Documents. Please delete any unneeded files.", vbExclamation + vbOKOnly, "Disk Quota Warning!"

		Else

			'We're fine.

			MsgBox "Free Space for your My Documents: " & Int(objDisk.FreeSpace / 1024 / 1024 ) & "Mb of " & Int(objDisk.Size / 1024 / 1024) & "Mb", vbInformation + vbOKOnly, "Disk Quota Information"

		End If

	End If

End If

Next

 

If anyone else needs it. :)

Posted
just out of interest, how do you get your "My Documents" or any mapped drive to report what they are allowed to use and not the total capacity of the server/drive it is hosted on?

 

would it not give the same message to all users on the same server/drive?

 

BoX

 

Linux/Samba File Server.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...