+ Post New Thread
Results 1 to 11 of 11
Scripts Thread, [Fixed] Script not working. File Quota check/reporting at Login. in Coding and Web Development; Having a thick moment. This script isn't working as expected. Any clues? Code: strComputer = "." Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" ...
  1. #1

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227

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

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

    Code:
    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

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,271
    Thank Post
    884
    Thanked 2,749 Times in 2,322 Posts
    Blog Entries
    11
    Rep Power
    785
    What is it doing wrong? You could ditch the for loop totally by adding the criteria into your query which may help

    Code:
    select * from Win32_MappedLogicalDisk where name = "Z:"
    Then just check that there are results and access them directly
    Last edited by SYNACK; 4th September 2008 at 05:51 PM.

  3. #3

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227
    Ok still having problems. I stripped everything down to a more basic script to test.

    Code:
    	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)

  4. #4
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    439
    Thank Post
    80
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    i used
    Code:
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    instead of

    Code:
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    and it seemed to work for me

    Box

  5. #5

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227
    Still the same error here.

  6. #6
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    439
    Thank Post
    80
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    does this work?

    Code:
    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

  7. #7

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227
    yes that works. I guess I should put the loop back in.

  8. #8
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    439
    Thank Post
    80
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    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
    Last edited by box_l; 5th September 2008 at 12:19 PM.

  9. #9

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227
    Ok, so back to my original script. All fixed and working!

    Code:
    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.

  10. #10

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227
    Quote Originally Posted by box_l View Post
    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.

  11. #11
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    439
    Thank Post
    80
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    oh OK.

    will test with my nas at home then.




SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 17
    Last Post: 20th March 2010, 12:51 AM
  2. Disk Quota Reporting
    By NeoS in forum Windows
    Replies: 16
    Last Post: 9th July 2007, 07:47 PM
  3. Replies: 4
    Last Post: 25th December 2006, 10:15 PM
  4. Replies: 4
    Last Post: 23rd March 2006, 07:27 AM
  5. Replies: 3
    Last Post: 1st March 2006, 01:08 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •