Announcement

Collapse
No announcement yet.

VBs - How to Create a VBscript for checking System's Drive Free Space with errorlevel

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBs - How to Create a VBscript for checking System's Drive Free Space with errorlevel

    Hi.
    I'm looking for a way to use VBscript to check the free space of the Systemdrive (usually drive c) but sometime it varies. I need the script to use errorlevel -1 for a value of freespace lower than XXX MB, and use the Message Box (popup) to announce that there is not enough free space.
    THX

  • #2
    Re: VBs - How to Create a VBscript for checking System's Drive Free Space with errorl

    Hi,

    This post I think is similar to yours: http://forums.petri.com/showthread.php?t=9414

    Ta
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

    Comment


    • #3
      Re: VBs - How to Create a VBscript for checking System's Drive Free Space with errorl

      Thanks.
      Your link was not very helpful, they are talking general stuff for the drive
      I have used this link
      http://kuldeepse.wordpress.com/2008/...o-file-system/
      along with if with accasion and WSCript.Quit(1) ---> errorcode
      but i have used "C:" instead of %systemdrive%, this one I didn't know how to do it,at least it works this way now.

      script:
      Moderator EDIT: "added [code] tags around the code"
      Code:
      dim fsoObject, sysdrv
      
          haveEnoughFreeSpace = false
          strComputer = "." 
          Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
          Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk",,48) 
          set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
          set sysDrv = fsoObject.GetDrive(fsoObject.GetDriveName("c:"))
              For Each objItem in colItems
          if (objItem.Name = sysDrv) then
              'if (objItem.DriveType = 3) then
                  'WScript.echo "Drive " & objItem.Caption & " free space: " & FormatNumber(objItem.FreeSpace/(1024^2), 0,0,0,0) & "MB"
                  if (objItem.FreeSpace/(1024^2) > 750) then
                      haveEnoughFreeSpace = true
                  end if
          end if
          Next
              
          if (haveEnoughFreeSpace = false) then
              msgTxt = " Service Pack 3 installation has failed!" & chr(13)
              msgTxt = msgTxt & " At least 750 MB free space is required to complete this installation." & chr(13)
              msgTxt = msgTxt & " Free up some space and rerun the Installation ."
              Msgbox msgTxt , 16, "Error"
              
              WScript.Quit(1)
          end if
          
          WScript.Quit (0)
      Thanks anyway, hope someone will use it and make it better.
      Last edited by Rems; 29th October 2008, 09:49.

      Comment


      • #4
        Re: VBs - How to Create a VBscript for checking System's Drive Free Space with errorl

        Originally posted by Mike_comsol View Post
        Thanks.
        Your link was not very helpful, they are talking general stuff for the drive
        I have used this link
        If you read the thread in the link with a bit more concentration you'll notice that they are not talking about "General stuff" but about a Script that will notify the user if the free Drivespace of a certain drive is lower than a specified value. In the script provided there the method for notification used is Wscript.Echo .
        Isn't that what you asked for originally???
        You did provide an alterative script that serves exactly the same purpose.
        So it's a case of Tomato / Tomato unless you ask questions about premeditated answers.


        Cheers
        Caesar's cipher - 3

        ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

        SFX JNRS FC U6 MNGR

        Comment

        Working...
        X