Announcement

Collapse
No announcement yet.

Drive space script

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

    Drive space script

    I've been using this script made by A.J. Gyomber for monitoring drive space. It works very well except now I want to monitor my laptop as well. However, if the laptop isn't on, I'll get an error about path not found. I'm not sure where to add the IF statement and exit out the step if no network connection found.

    Here's the codes:

    <pre class="ip-ubbcode-code-pre">Sub Main()

    GetSpace "C:", "t8"
    GetSpace "\\pic_frame\c$", "t9"

    End Sub

    Sub GetSpace(byref DrivePath, byref DeviceCode)

    Dim fso, drv, s
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set drv = fso.GetDrive(fso.GetDriveName(DrivePath))
    s = FormatNumber(drv.TotalSize / 1073741824, 2)
    s = s & " Total Gb / "
    s = s & FormatNumber(drv.FreeSpace / 1073741824, 2) & " Gb Free"

    hs.SetDeviceString DeviceCode, "&lt;img src='hard_drive.gif' align=absmiddle&gt;" & " " & s, TRUE

    Set drv = Nothing
    Set fso = Nothing

    End Sub
    </pre>

    What I'm trying to do is to keep the same status text if it can't find the laptop and skip the check so it doesn't return error.

    Your help is much appreciated.

    Simon

    #2
    A simple ON ERROR RESUME NEXT at the top of the script should do it.

    Justin

    Comment


      #3
      Justin,

      Thanks a lot, that did the trick.

      Simon

      Comment


        #4
        From time to time, I get a message box from Homeseer telling me the script is taking a long time and ask me if I want to terminate it. It happens when one computer is offline. I made the following changes in the main sub but I can't get the parameter for "ping" to work:

        <pre class="ip-ubbcode-code-pre">Sub Main()

        Dim alive
        On Error Resume Next
        GetSpace "C:", "t8"
        GetSpace "\\pic_frame\c$", "t9"
        alive = ping(192.168.1.101)
        if alive = 0 then
        GetSpace "\\simon_main\c$", "t10"
        GetSpace "\\simon_main\d$", "t11"
        GetSpace "\\simon_main\v$", "t12"
        end if

        End Sub </pre>

        I checked the Homeseer help on ping but no example provided. When I run the script, it tells me I'm missing a ")" on "alive = ping(192.168.1.101)

        Thanks,

        Simon

        Comment


          #5
          With the help from Jeff, it's working now. The problem is hs.ping() requires a string and not the real IP address. Therefore, I made the following changes and now the codes are:

          <pre class="ip-ubbcode-code-pre">Sub Main()

          Dim host
          host = "192.168.1.101"
          GetSpace "C:", "t8"
          GetSpace "\\pic_frame\c$", "t9"
          if hs.ping(CStr(host),5) = 0 then
          msgbox "Yeah, it works"
          GetSpace "\\simon_main\c$", "t10"
          GetSpace "\\simon_main\d$", "t11"
          GetSpace "\\simon_main\v$", "t12"
          end if

          End Sub</pre>

          The ping command will time out in 5 seconds if the computer is off and not check for hard drive space.

          Thanks Jeff for his assistance.

          Simon

          [This message was edited by htsource on Sunday, 08 September 2002 at 06:37 PM.]

          Comment


            #6
            HTSource,

            Could you send me a copy of the drive space script. I can't seem to find it anywhere.

            plane_pilot2000 AT yahoo.com

            Comment


              #7
              Plane_Guy,

              Sorry for the delay getting back to you, I can't find your email address so I'm uploading my version here. Hope it helps,

              Simon
              Attached Files

              Comment


                #8
                I now have the script up and running, and love it . I was wondering if anyone has a modification that would monitor free space and set a device code as an alarm?? (e.g. drivespace less than 1GB, set x10 device y1 to on).

                Any Ideas?

                Thanks in advance

                Tom

                Comment


                  #9
                  Here is the script that I use and it sets a message if the free space drops below a user selectable limit.

                  <pre class="ip-ubbcode-code-pre">

                  Sub Main()
                  ' Set the value for the low disk space warning message in GB
                  WarningValue = 1

                  ' Set the House and Unit code for the device to hold the warning message
                  WarningCode = "s3"

                  ' Reset the message prior to reading the drives
                  hs.SetDeviceString WarningCode, "Disk Space Sufficient", True


                  GetSpace "C:", "s1", WarningValue, WarningCode
                  GetSpace "D:", "s2", WarningValue, WarningCode

                  End Sub

                  Sub GetSpace(byref DrivePath, byref DeviceCode, byRef warnVal, byRef warnCode)

                  Dim fso, drv, s

                  Set fso = CreateObject("Scripting.FileSystemObject")
                  Set drv = fso.GetDrive(fso.GetDriveName(DrivePath))
                  s = FormatNumber(drv.TotalSize / 1073741824, 2)
                  s = s & " Total Gb / "
                  Free = CDbl(FormatNumber(drv.FreeSpace / 1073741824, 2))
                  s = s & Free & " Gb Free"

                  If Free &lt; warnVal Then
                  hs.SetDeviceString warnCode, "&lt;span style=""color: RED""&gt; Low Disk Space Warning on drive " & DrivePath & " &lt;/span&gt;", True
                  End If

                  hs.SetDeviceString DeviceCode, s, True

                  Set drv = Nothing
                  Set fso = Nothing


                  End Sub


                  </pre>

                  -Rupp
                  💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                  Comment


                    #10
                    Rupp

                    Works like a charm!

                    Thanks!

                    T1

                    Comment


                      #11
                      Old Script

                      This is an old script that I have been using for some time. Just added some new drives, so was adding to the script. Was just wondering if anyone knew how to make a device code that added the total drive space of all drives?

                      Thanks

                      Comment


                        #12
                        Nice script.. I just have one problem with the network drives:

                        GetSpace "\\10.1.1.50\c$", "t2"

                        <table border="0" cellpadding="0" cellspacing="2" width="100%"><tbody><tr><td colspan="3" class="LOGType1" align="left">
                        </td><td colspan="8" class="LOGEntry1" align="left">Running script, script run or compile error in file: drivespace.txt76:Path not found in line 36 More info: Path not found</td></tr></tbody></table>
                        Line 36: Set drv = fso.GetDrive(fso.GetDriveName(DrivePath))

                        I can access this drive when typing Start/Run "\\10.1.1.50\c$" from my HS machine. Any ideas?

                        Comment


                          #13
                          Originally posted by DJF3 View Post
                          Nice script.. I just have one problem with the network drives:

                          GetSpace "\\10.1.1.50\c$", "t2"

                          I can access this drive when typing Start/Run "\\10.1.1.50\c$" from my HS machine. Any ideas?
                          Are you running HomeSeer as a service?

                          Comment


                            #14
                            Yes, HS is running as a service.. (using services.msc to stop and start HS2).

                            Ah, I might see what you're getting at. HS2 is running as a service under userid "LocalSystem" account that is allowed to interact with the desktop. So I might have to grant access to this user (so it can access the \\10.1.1.50\c$) or have HS2 run under a different user ID?

                            -What would the impact be of running HS2 under an account in the administrator group vs a LocalSystem account?
                            -How could I grant access to the LocalSystem account so it can 'read' the free diskspace on a network drive?

                            I think that when I mapped this network drive as a local drive (so mapping \\10.1.1.50\c$ to Z and then pointing the script to Z: provided a permissions error. (not sure, can't try right now)

                            Tnx
                            DJ

                            Comment


                              #15
                              Originally posted by DJF3 View Post
                              Yes, HS is running as a service.. (using services.msc to stop and start HS2).
                              When you run HS as a service, it is accessing everything under the "Local System" account. So when it tries to access another machine over the network, it can't as it doesn't have an account to login to the remote machine.

                              Now, I'm assuming you don't have these machines in an AD domain.

                              There are various ways around this. The easiest is to create an account on the local machine (and the remote machine) with the same username and password. Modify the HomeSeer service via the "Log On" tab, click "This account" and enter the username and password for the account you just created. Just one thing, when you enter the username add .\ in front of it. Eg If you create an account called HomeSeer, enter the username as .\HomeSeer

                              Now when the HS service tries to access a remote machine, it now has a username and password it can use to authenticate to the remote machine.
                              If the remote machine has an account with the same name and password, it'll work.

                              Ross.

                              Comment

                              Working...
                              X