Random Number Function in Range

    Function funRandomNumber(lowerbound As Integer, upperbound As Integer) As Integer

        funRandomNumber = Int((upperbound - lowerbound + 1) * Rnd() + lowerbound)

    End Function


Disk Info

Imports System.Management

Imports System.Security.Principal

Imports Microsoft.Win32

    Function GetDisksInfo(sComputerNameToQuery As String) As String

        Dim objDiskDetails As ManagementObjectSearcher

        Dim objMgmt As ManagementObject

        Dim scope As ManagementScope

        Dim options As New ConnectionOptions

        options.Username = "elevatedUser"

        options.SecurePassword = ToSecureString("password")

        scope = New ManagementScope("\\" & sComputerNameToQuery & "\root\cimv2", IIf(sComputerNameToQuery = ".", Nothing, options))

        scope.Connect()

        objDiskDetails = New ManagementObjectSearcher(scope, New ObjectQuery("Select * from Win32_LogicalDisk WHERE DriveType=3"))

        Dim pctFreeSpace, strFreeSpace, strusedSpace, strDiskSize

        Dim txt As String = ""

        Try

            For Each objMgmt In objDiskDetails.Get

                pctFreeSpace = Int((objMgmt("FreeSpace") / objMgmt("Size") * 1000) / 10)

                strDiskSize = Int(objMgmt("Size") / 1073741824) & ""

                strFreeSpace = Int(objMgmt("FreeSpace") / 1073741824) & ""

                strusedSpace = Int((objMgmt("Size") - objMgmt("FreeSpace")) / 1073741824) & ""

                txt += objMgmt("name") & vbTab & strDiskSize & vbTab & strusedSpace & vbTab & strFreeSpace & vbTab & pctFreeSpace & vbCrLf

            Next

        Catch

            txt += vbTab & "0" & vbTab & "0" & vbTab & "0" & vbTab & "0" & vbCrLf

        End Try

        GetDisksInfo = txt

    End Function

Uptime for a server

    Function funGetUptime(sComputer As String) As String

        Dim pc As PerformanceCounter = New PerformanceCounter("System", "System Up Time")

        pc.MachineName = sComputer ' Must have permissions over the machine in order to gain this.

        Try

            pc.NextValue()

        Catch ex As Exception

            Return ex.Message.ToString

        End Try

        Dim duration As TimeSpan = TimeSpan.FromSeconds(pc.NextValue())

        Return (duration.Days & " Days " & duration.Hours & " Hours " & duration.Minutes & " Minutes " & duration.Seconds & " Seconds")

    End Function


DateTime.Now.Subtract(duration)


Example of File Version comparison

Dim oFileVer As FileVersionInfo = FileVersionInfo.GetVersionInfo(oFile.sPath)

  'If CDbl(Replace(oFile.sVersion, ".", ",")) >= CDbl(Replace(oFileVer.FileVersion, ".", ",")) Then

  If String.Compare(oFile.sVersion, oFileVer.FileVersion) <= 0 Then

   'we're ok

    funWriteWordinColor("Good version: (current) " & oFileVer.FileVersion & " >= (needed) " & oFile.sVersion & vbCrLf, ConsoleColor.Green)

   Else

      funWriteWordinColor("Incorrect version (" & oFile.sFileName & ") : (current) " & oFileVer.FileVersion & " < (needed) " & oFile.sVersion & vbCrLf, ConsoleColor.Red)

   End If