Results 1 to 13 of 13

Thread: Memory

  1. #1

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    Hi, anyone knows how to check for total memory a computer has and how much is being used?
    License to Program

    007

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    start->programs->accessories->systemtools->systemmonitor

    then choose edit->additem->memorymanager

    then choose unused physical memory (at the bottom)

  3. #3
    Guest
    Use GetFreeDiskSpaceEx. Add the following to a Form with a CommandButton
    Code:
    Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, lpFreeBytesAvailableToCaller As ULARGE_INTEGER, lpTotalNumberOfBytes As ULARGE_INTEGER, lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long
    Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Private Type ULARGE_INTEGER
      LowPart As Long
      HighPart As Long
    End Type
    
    Dim tmp As String
    Dim FreeUser As ULARGE_INTEGER
    Dim Total As ULARGE_INTEGER
    Dim FreeSys As ULARGE_INTEGER
    Dim Temp As Currency
    Dim fTemp As Currency
    
    Private Sub Command1_Click()
        GetDiskFreeSpaceEx "C:\", FreeUser, Total, FreeSys
        CopyMemory Temp, Total, 8
        CopyMemory fTemp, FreeUser, 8
        Print "Total Space: " & (CCur(Temp) * 10000) / 1000000000 & " GB"
        Print "Free Space: " & (CCur(fTemp) * 10000) / 1000000000 & " GB"
        Print "Used Space: " & ((CCur(Temp) * 10000) / 1000000000) - ((CCur(fTemp) * 10000) / 1000000000) & " GB"
    End Sub

  4. #4

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    Thank you Megatron!
    License to Program

    007

  5. #5

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    Meg!

    Something doesn't seem right. How come its returning really big numbers?

    It looks like it is returning the size of the hard drive not the memory.
    License to Program

    007

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Megatrons code gives you the size of your C drive.

  7. #7
    Lively Member
    Join Date
    Apr 2000
    Posts
    110

    Wink Use this

    To get memory information on your system, use the GlobalMemoryStatus API.

    Code:
    'Nicked from API guide... ;)
    Option explicit
    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
    Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
    Private Sub Form_Load()
    
        Dim MemStat As MEMORYSTATUS
        'retrieve the memory status
        GlobalMemoryStatus MemStat
        MsgBox "You have" + Str$(MemStat.dwTotalPhys / 1024) + " Kb total memory and" + Str$(MemStat.dwAvailPageFile / 1024) + " Kb available PageFile memory."
    End Sub
    You can get loads of information from the MEMORYSTATUS structure that is returned.

    Later

    REM
    "Innovate, don't immitate."

  8. #8

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    I am looking for the memory capacity and usage.

    Also, I am looking for the serial number of the computer.
    License to Program

    007

  9. #9
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Code:
    Option Explicit
    
    Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
    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
    
    Private Sub Main()
      Dim T As MEMORYSTATUS
      Call GlobalMemoryStatus(T)
      
      Dim str_Data As String
      str_Data = "Length: " & vbTab & vbTab & T.dwLength & vbCrLf & _
                "MemoryLoad: " & vbTab & T.dwMemoryLoad & vbCrLf & _
                "TotalPhys: " & vbTab & T.dwTotalPhys & vbCrLf & _
                "AvailPhys: " & vbTab & T.dwAvailPhys & vbCrLf & _
                "TotalPageFile: " & vbTab & T.dwTotalPageFile & vbCrLf & _
                "AvailPageFile: " & vbTab & T.dwAvailPageFile & vbCrLf & _
                "TotalVirtual: " & vbTab & T.dwTotalVirtual & vbCrLf & _
                "AvailVirtual: " & vbTab & T.dwAvailVirtual
      MsgBox str_Data
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  10. #10

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    Thanks everyone, but I think I am going to stick with Rem's code. Why did you divide it by 1024 and do you know how to get the computer's serial number?
    License to Program

    007

  11. #11
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    It's devided with 1024 because it's displayed in bytes, and to make it KB you should devide it with 1024, for MB devide that with 1024, to make it GB divide that with 1024, and so on.

    I'm not sure how to get the serial, just do a search on these forums
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  12. #12
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Code:
    Option Explicit
    Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
    
    Private Sub Main()
      Dim lng_VolName As String
      Dim lng_SystemFileType As String
      Dim lng_SerialNumber As Long
      Dim lng_MaxLen As Long
      Dim lng_SystemFlags As Long
      Call GetVolumeInformation("C:\", lng_VolName, Len(lng_VolName), lng_SerialNumber, lng_MaxLen, lng_SystemFlags, lng_SystemFileType, Len(lng_SystemFileType))
      
      'PURPOSE: Format the serial number properly.
      Dim str_SerialNumber As String
      str_SerialNumber = Trim(Hex(lng_SerialNumber))
      str_SerialNumber = String(8 - Len(str_SerialNumber), "0") & str_SerialNumber
      str_SerialNumber = Left(str_SerialNumber, 4) & "-" & Right(str_SerialNumber, 4)
      MsgBox "Serial Number: " & str_SerialNumber
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  13. #13
    Junior Member
    Join Date
    Feb 2000
    Location
    Gig Harbor, WA, USA
    Posts
    25
    I wrote a module that lets you get some info about your hard drive, one of the things available is the serial number. To call it, you need to Dim Var As DriveInformation, then GetDriveInfo("C:", Var). .SerialNumber is the serial in Hex form, .SerialLong is the true serial number. Note that a computer doesn't have a serial number, but each hard drive does. Also note that serial numbers are changed when the drive is formatted, partitioned, etc.

    Code:
    Attribute VB_Name = "DriveInfo"
    Private Declare Function GetVolumeInformation _
        Lib "kernel32" Alias "GetVolumeInformationA" _
        (ByVal lpRootPathName As String, _
        ByVal lpVolumeNameBuffer As String, _
        ByVal nVolumeNameSize As Long, _
        lpVolumeSerialNumber As Long, _
        lpMaximumComponentLength As Long, _
        lpFileSystemFlags As Long, _
        ByVal lpFileSystemNameBuffer As String, _
        ByVal nFileSystemNameSize As Long) As Long
    
    Public Type DriveInformation
        DriveLetter As String * 1
        VolumeLabel As String
        SerialNumber As String * 9
        SerialLong As Long
        FileSystem As String
        
        FilesAreCaseSensitive As Boolean
        CaseIsPreserved As Boolean
        UnicodeSupported As Boolean
        SupportsACLS As Boolean
        SupportsFileCompression As Boolean
        VolumeIsCompressed As Boolean
    End Type
    
    Private Const FS_CASE_SENSITIVE = &H1
    Private Const FS_CASE_IS_PRESERVED = &H2
    Private Const FS_UNICODE_STORED_ON_DISK = &H4
    Private Const FS_PERSISTENT_ACLS = &H8
    Private Const FS_FILE_COMPRESSION = &H10
    Private Const FS_VOL_IS_COMPRESSED = &H8000
    
    Public Sub GetDriveInfo(RootPath As String, DriveVar As DriveInformation)
        Dim Flags, Serial As Long
        Dim System As String * 32
        Dim Lbl As String * 32
        With DriveVar
            Call GetVolumeInformation(RootPath, Lbl, 32, .SerialLong, 0&, Flags, System, 32)
            
            'Set Drive Information
            .DriveLetter = Left$(RootPath, 1)
            .SerialNumber = Format(String(8 - Len(Hex(.SerialLong)), "0") & Hex(.SerialLong), "@@@@-@@@@")
            .VolumeLabel = Left$(Lbl, InStr(1, Lbl, vbNullChar) - 1)
            .FileSystem = Left$(System, InStr(1, System, vbNullChar) - 1)
            
            'Set Flags
            .FilesAreCaseSensitive = Flags And FS_CASE_SENSITIVE
            .CaseIsPreserved = Flags And FS_CASE_IS_PRESERVED
            .UnicodeSupported = Flags And FS_UNICODE_STORED_ON_DISK
            .SupportsACLS = Flags And FS_PERSISTENT_ACLS
            .SupportsFileCompression = Flags And FS_FILE_COMPRESSION
            .VolumeIsCompressed = Flags And FS_VOL_IS_COMPRESSED
        End With
    End Sub
    (¯`·.¸¸.·´¯`·->Cromas<-·´¯`·.¸¸.·´¯)
    Teenage Programmer
    Formerly known as ShadowCrawler

    E-Mail: [email protected]
    ICQ: 9872708
    AIM: VotchOut

Posting Permissions

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



Click Here to Expand Forum to Full Width