Jump to content

Recommended Posts

Posted

Hello Forum Friends, could you please help me once again.

As I'm studying alone and I have you as a reference, could you teach me what this error means and why and how to correct it?

Thanks in advance to everyone who helps me.

The error is:

(25) : ==> Variable must be of type "Object".:
Location $memoryTotal = Round($memoryObj.TotalPhysicalMemory / 1024 / 1024 / 1024, 2)
Location $memoryTotal = Round($memoryObj^ ERROR

 

#include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>
    #include <String.au3>
    #include <GuiButton.au3>
    #include <ComboConstants.au3>
    #include <Constants.au3>
    #include <ScreenCapture.au3>
    #include <MsgBoxConstants.au3>
    #include <Array.au3>
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>
    #include <EditConstants.au3>
    #include <GuiStatusBar.au3>
    #include <AutoItConstants.au3>
    #include <GuiTab.au3>
    #include <Security.au3>
    #include <Misc.au3>


#Include <WinAPIFiles.au3>

Func GetMemoryInfo()
    Local $memoryObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_ComputerSystem=@")
    Local $memoryTotal = Round($memoryObj.TotalPhysicalMemory / 1024 / 1024 / 1024, 2) ; GB
    Local $memoryUsage = Round(($memoryObj.TotalPhysicalMemory - $memoryObj.FreePhysicalMemory) / $memoryObj.TotalPhysicalMemory * 100, 2) ; Porcentagem

    Local $memorySlots = ""
    Local $memorySlotsUsed = 0
    Local $memorySlotsFree = 0
    Local $memoryType = ""

    Local $memorySlotsObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_PhysicalMemory")
    For $slot In $memorySlotsObj
        $memorySlots &= "Slot: " & $slot.DeviceLocator & ", Tipo: " & $slot.MemoryType & @CRLF
        If $slot.MemoryType = 0 Then
            $memoryType = "DDR Unknown"
        ElseIf $slot.MemoryType = 1 Then
            $memoryType = "Other"
        ElseIf $slot.MemoryType = 2 Then
            $memoryType = "DRAM"
        ElseIf $slot.MemoryType = 3 Then
            $memoryType = "Synchronous DRAM"
        ElseIf $slot.MemoryType = 4 Then
            $memoryType = "Cache DRAM"
        ElseIf $slot.MemoryType = 5 Then
            $memoryType = "EDO"
        ElseIf $slot.MemoryType = 6 Then
            $memoryType = "EDRAM"
        ElseIf $slot.MemoryType = 7 Then
            $memoryType = "VRAM"
        ElseIf $slot.MemoryType = 8 Then
            $memoryType = "SRAM"
        ElseIf $slot.MemoryType = 9 Then
            $memoryType = "RAM"
        ElseIf $slot.MemoryType = 10 Then
            $memoryType = "ROM"
        ElseIf $slot.MemoryType = 11 Then
            $memoryType = "Flash"
        ElseIf $slot.MemoryType = 12 Then
            $memoryType = "EEPROM"
        ElseIf $slot.MemoryType = 13 Then
            $memoryType = "FEPROM"
        ElseIf $slot.MemoryType = 14 Then
            $memoryType = "EPROM"
        ElseIf $slot.MemoryType = 15 Then
            $memoryType = "CDRAM"
        ElseIf $slot.MemoryType = 16 Then
            $memoryType = "3DRAM"
        ElseIf $slot.MemoryType = 17 Then
            $memoryType = "SDRAM"
        ElseIf $slot.MemoryType = 18 Then
            $memoryType = "SGRAM"
        ElseIf $slot.MemoryType = 19 Then
            $memoryType = "RDRAM"
        ElseIf $slot.MemoryType = 20 Then
            $memoryType = "DDR"
        ElseIf $slot.MemoryType = 21 Then
            $memoryType = "DDR2"
        ElseIf $slot.MemoryType = 22 Then
            $memoryType = "DDR2 FB-DIMM"
        ElseIf $slot.MemoryType = 24 Then
            $memoryType = "DDR3"
        ElseIf $slot.MemoryType = 25 Then
            $memoryType = "FBD2"
        ElseIf $slot.MemoryType = 26 Then
            $memoryType = "DDR4"
        ElseIf $slot.MemoryType = 27 Then
            $memoryType = "LPDDR"
        ElseIf $slot.MemoryType = 28 Then
            $memoryType = "LPDDR2"
        ElseIf $slot.MemoryType = 29 Then
            $memoryType = "LPDDR3"
        ElseIf $slot.MemoryType = 30 Then
            $memoryType = "LPDDR4"
        ElseIf $slot.MemoryType = 31 Then
            $memoryType = "LPDDR4X"
        EndIf

        If StringInStr($slot.DeviceLocator, "DIMM") Then
            $memorySlotsUsed += 1
        Else
            $memorySlotsFree += 1
        EndIf
    Next

    MsgBox(0, "Informações de Memória", "Memória RAM Total: " & $memoryTotal & " GB" & @CRLF & _
                                    "Porcentagem de Uso de Memória RAM: " & $memoryUsage & "%" & @CRLF & _
                                    "Slots Utilizados: " & $memorySlotsUsed & @CRLF & _
                                    "Slots Livres: " & $memorySlotsFree & @CRLF & _
                                    "Tipos de Memória: " & $memoryType & @CRLF & _
                                    "Posições dos Slots: " & @CRLF & $memorySlots)
EndFunc

Func GetDiskInfo()
    Local $diskObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_LogicalDisk.DeviceID='C:'")
    Local $diskTotal = Round($diskObj.Size / 1024 / 1024 / 1024 / 1024, 2) ; TB
    Local $diskUsage = Round(($diskObj.Size - $diskObj.FreeSpace) / $diskObj.Size * 100, 2) ; Porcentagem

    Local $diskTech = ""

    Local $diskPartitionsObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_DiskDrive")
    For $disk In $diskPartitionsObj
        $diskTech = $disk.MediaType
        ExitLoop
    Next

    MsgBox(0, "Informações de Disco", "Tamanho Total do Disco: " & $diskTotal & " TB" & @CRLF & _
                                    "Porcentagem de Uso do Disco: " & $diskUsage & "%" & @CRLF & _
                                    "Tecnologia do Disco: " & $diskTech)
EndFunc

Func GetProcessorInfo()
    Local $cpuObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_Processor=@")
    Local $cpuName = $cpuObj.Name

    MsgBox(0, "Informações do Processador", "Nome do Processador: " & $cpuName)
EndFunc

Func GetBIOSInfo()
    Local $biosObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_BIOS=@")
    Local $biosVersion = $biosObj.SMBIOSBIOSVersion
    Local $biosManufacturer = $biosObj.Manufacturer
    Local $computerSerial = $biosObj.SerialNumber

    MsgBox(0, "Informações da BIOS", "Versão da BIOS: " & $biosVersion & @CRLF & _
                                    "Fabricante da BIOS: " & $biosManufacturer & @CRLF & _
                                    "Número de Série do Computador: " & $computerSerial)
EndFunc

Func GetSystemInfo()
    Local $computerSystemObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_ComputerSystem=@")
    Local $computerName = $computerSystemObj.Name
    Local $chassisType = $computerSystemObj.ChassisTypes(0)
    Local $networkDomain = $computerSystemObj.Domain
    Local $model = $computerSystemObj.Model
    Local $registeredUser = $computerSystemObj.UserName

    MsgBox(0, "Informações do Sistema", "Hostname: " & $computerName & @CRLF & _
                                    "Tipo de Chassi: " & $chassisType & @CRLF & _
                                    "Domínio de Rede: " & $networkDomain & @CRLF & _
                                    "Modelo do Computador: " & $model & @CRLF & _
                                    "Usuário Registrado: " & $registeredUser)
EndFunc

Func GetOSInfo()
    Local $osObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_OperatingSystem=@")
    Local $osFullName = $osObj.Caption
    Local $osVersionBuild = $osObj.BuildNumber
    Local $osInstallDate = $osObj.InstallDate
    Local $osLastBoot = $osObj.LastBootUpTime
    Local $osLocalDateTime = $osObj.LocalDateTime
    Local $osVersion = $osObj.Version

    Local $osRelease = StringTrimLeft($osVersion, 4)

    MsgBox(0, "Informações do Sistema Operacional", "Nome Completo do SO: " & $osFullName & @CRLF & _
                                    "Versão da Build: " & $osVersionBuild & @CRLF & _
                                    "Data de Instalação: " & $osInstallDate & @CRLF & _
                                    "Último Boot: " & $osLastBoot & @CRLF & _
                                    "Data e Hora Local: " & $osLocalDateTime & @CRLF & _
                                    "Número de Release: " & $osRelease)
EndFunc

Func GetLoggedInUserInfo()
    Local $userObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_ComputerSystem=@")
    Local $user = $userObj.UserName

    Local $profilesObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_UserProfile")
    Local $profileCount = 0
    For $profile In $profilesObj
        $profileCount += 1
    Next

    Local $loggedUserObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_ComputerSystem=@")
    Local $loggedFullName = $loggedUserObj.UserName
    Local $loggedUserName = $loggedUserObj.UserName

    MsgBox(0, "Informações do Usuário Logado", "Usuário Ativo: " & $user & @CRLF & _
                                    "Quantidade de Perfis: " & $profileCount & @CRLF & _
                                    "Nome Completo do Usuário Logado: " & $loggedFullName & @CRLF & _
                                    "Nome de Usuário Logado: " & $loggedUserName)
EndFunc

GetMemoryInfo()
GetDiskInfo()
GetProcessorInfo()
GetBIOSInfo()
GetSystemInfo()
GetOSInfo()
GetLoggedInUserInfo()

 

 

Posted

The help file is your friend :)
ObjGet sets macro @error. Use Consolewrite to write this code to the Scite output pane.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I don't know where you got this code, but there is quite a number of issues with it.  Most important, FreePhysicalMemory does not exist (at least on Win10).  So you will need to get those informations elsewhere.  Look at MemGetStats.

Posted (edited)
;~     Local $memoryObj = ObjGet("winmgmts:\\.\root\cimv2:Win32_ComputerSystem=@")
;~     Local $memoryUsage = Round(($memoryObj.TotalPhysicalMemory - $memoryObj.FreePhysicalMemory) / $memoryObj.TotalPhysicalMemory * 100, 2) ; Porcentagem


        $oMemoryObj = ObjGet("winmgmts:\\.\root\cimv2" )
        If @error Then
        Else
            $oMemoryObj_Items = $oMemoryObj.ExecQuery("select TotalPhysicalMemory from Win32_ComputerSystem")
            If IsObj($oMemoryObj_Items) Then
                For $oItem In $oMemoryObj_Items
                    Local $iMemoryTotal = $oItem.TotalPhysicalMemory
                Next
            EndIf
        EndIf
        $iMemoryTotal = Round($iMemoryTotal / 1024 / 1024 / 1024, 2) ; GB

In the above snippet, I replaced the top 2 lines with the bottom 11. Most of the variables are renamed so keep that in mind if you use it.

Also, as @Nine said, FreePhysicalMemory isn't a property in Win32_ComputerSystem, so that will info have to come from somewhere else.

 

Edited by rsn
Posted

Sorry for the delay in response.
I thank everyone.
And I'm still studying the reason for the error.
Analyzing this last code I will try to find out.

I translated the manual for better understanding.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...