home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 1999-09-06 | 4.0 KB | 140 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "cSysInfo"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Option Explicit
-
- ' API Functions For obtaing the WInDir and SysDir.
- Private Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
- Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
-
- ' API Function to retrive the memory data. ***API TIP***
- ' When called passing in a predefined type with the appropriate members,
- ' the members will then be assigned with the needed data.
- Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
-
- ' Type to store all retrieved _
- data about the sys's memory.
- Private Type MEMORYSTATUS
- dwLength As Long
- dwMemoryLoad As Long
- dwTotalPhys As Long
- dwAvailPhys As Long
- dwTotalPageFile As Long
- dwAvailPageFile As Long
- dwTotalVirtual As Long
- dwAvailVirtual As Long
- End Type
-
-
- Const Frmt As String = "###,###,###,###"
- Const skb As String = " Kbyte"
- Const nkb As Long = 1024
-
-
-
-
- '--- this method will handle only the retrieving of the sysinfo.
- '--- it will be sent by SendSysInfo
-
- Sub GetSysInfo()
-
- Dim i As Integer, ii As Integer
- Dim SysInfo(9) As String
- Dim SysDirs(2) As String, Mem(7) As String
- Dim MemStats As MEMORYSTATUS
-
-
- ' get the Windows Directory
- SysDirs(1) = WinDir
- SysDirs(2) = SysDir
-
- ' get the memory status
- MemStats.dwLength = Len(MemStats)
- ' retrieve the memory data
- GlobalMemoryStatus MemStats
-
- ' format the results int a string array
- Mem(1) = Format$(MemStats.dwMemoryLoad, Frmt) & " % used"
- Mem(2) = Format$(MemStats.dwTotalPhys / nkb, Frmt) & skb
- Mem(3) = Format$(MemStats.dwAvailPhys / nkb, Frmt) & skb
- Mem(4) = Format$(MemStats.dwTotalPageFile / nkb, Frmt) & skb
- Mem(5) = Format$(MemStats.dwAvailPageFile / nkb, Frmt) & skb
- Mem(6) = Format$(MemStats.dwTotalVirtual / nkb, Frmt) & skb
- Mem(7) = Format$(MemStats.dwAvailVirtual / nkb, Frmt) & skb
-
-
- ' Package the retrieved data.
- For i = 1 To 2
- SysInfo(i) = SysDirs(i)
- For ii = 3 To 10
- SysInfo(ii) = Mem(ii - 2)
- If (ii - 2) = 7 Then Exit For
- Next
- Next
-
- Dim info As String
-
- info = SysInfo(1) & ";" & SysInfo(2) & ";" & SysInfo(3) & ";" _
- & SysInfo(4) & ";" & SysInfo(5) & ";" & SysInfo(6) & ";" _
- & SysInfo(7) & ";" & SysInfo(8) & ";" & SysInfo(9) & ";"
-
- SendSysInfo info
- End Sub
-
-
- Private Sub SendSysInfo(strInfo As String)
- '
- ' the data will be sent in packaged form to the Client.
- ' We must use another divider besides "," when sending
- ' data that contains nescasary commas.
-
- ' at the same time you must be ready to accept this from the client
- SendData "SysInfo@" & strInfo
- End Sub
-
-
-
-
- ' --- Method to retrieve the windows dir
-
- Private Function WinDir(Optional ByVal AddSlash As Boolean = False) As String
-
- Dim t As String * 255
- Dim i As Long
-
- i = GetWindowsDirectory(t, Len(t))
- WinDir = Left(t, i)
-
- If (AddSlash = True) And (Right(WinDir, 1) <> "\") Then
- WinDir = WinDir & "\"
- ElseIf (AddSlash = False) And (Right(WinDir, 1) = "\") Then
- WinDir = Left(WinDir, Len(WinDir) - 1)
- End If
-
- End Function
-
-
- ' --- Method to retrieve the windows\system dir
-
- Private Function SysDir(Optional ByVal AddSlash As Boolean = False) As String
-
- Dim t As String * 255
- Dim i As Long
-
- i = GetSystemDirectory(t, Len(t))
- SysDir = Left(t, i)
-
- If (AddSlash = True) And (Right(SysDir, 1) <> "\") Then
- SysDir = SysDir & "\"
- ElseIf (AddSlash = False) And (Right(SysDir, 1) = "\") Then
- SysDir = Left(SysDir, Len(SysDir) - 1)
- End If
-
- End Function
-