How do capture System information using vba into Excel

Hi There,

I want to capture information about a users machine into a spreadsheet.  How do I capture the following information using vba:
(just need to know how to get the information - I can put this into a spreadsheet)

Total Memory
Free hardware space
Processing speed

Thanks in advance.

Mark
SuperLightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oferamCommented:
3 commands:
1) wmic /node:"ComputerName" /USER:"Username" /Password:password" memlogical get TotalPhysicalMemory /format:csv
2) wmic /node:"ComputerName" /USER:"Username" /Password:password" wmic logicalDisk get FileSystem,FreeSpace /format:csv
3) wmic /node:"ComputerName" /USER:"Username" /Password:password" cpu get MaxClockSpeed, Name /format:csv

Good luck
0
SuperLightAuthor Commented:
Thanks oferam,

Could you expand on this a bit.  Do you have some sample code to show it in context.

Does wmic need a specific reference?
Is the information I'm seeking available without quoting a user and password (I won't have access to this information)

Thanks

Mark
0
SuperLightAuthor Commented:
Hi There,

Found the following code and it works a treat!  Hope this helps anyone else with a similar problem.

Thanks

Mark
Sub Main()

Dim strOS As String

strOS = GetOSName("Win32_OperatingSystem")

'Returns Memory
Debug.Print GetOSInfo("tblWin32_OperatingSystem", strOS, "MEMORY")
'Returns FreeStorage and Total Storage
Debug.Print GetOSInfo("tblWin32_OperatingSystem", strOS, "FREESTORAGE")

End Sub


Function GetOSName(strClassName As String) As String
On Error GoTo Err_GetOSName

    Dim objWMIService As Object
    Dim colItems As Object
    Dim objItem As Object
    Dim strComputer As String
    Dim strOSName As String
    Dim strWQL As String
    
    strComputer = "."
    
    strWQL = "SELECT * FROM " & strClassName

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    
    Set colItems = objWMIService.ExecQuery(strWQL, , 48)

    For Each objItem In colItems
        ' Get the Value of the Name Property
        strOSName = objItem.Name
    Next
    
    GetOSName = strOSName
    
Exit_GetOSName:
    ' Release Memory
    Set objItem = Nothing
    Set colItems = Nothing
    Set objWMIService = Nothing
    Exit Function

Err_GetOSName:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ")" & _
    " In procedure GetOSName"
    Resume Exit_GetOSName

End Function

Function GetOSInfo(strTableName As String, ByVal strOSName As String, strCase As String) As String

On Error GoTo Err_GetOSInfo
    Dim objWMIService As Object
    Dim colItems As Object
    Dim objItem As Object
    Dim strComputer As String
    Dim strWMIQuery As String
    Dim strWMINamespace As String
     
    strComputer = "."

    Select Case UCase(strCase)
        Case "MEMORY"
            ' We use strOSName to specify the value of the Key Property to get the "instance" of the
            ' Win32_OperatingSystem Class we are accessing in order to get the Property Values
            
            strWMIQuery = ":Win32_OperatingSystem.Name='" & strOSName & "'"

            Set objWMIService = GetObject("winmgmts:\\" & _
            strComputer & "\root\CIMV2" & strWMIQuery)
    
            For Each objItem In objWMIService.Properties_
                Select Case objItem.Name
                    Case "TotalVisibleMemorySize"
                        'TotalVisibleMemorySize = Memory
                        GetOSInfo = WorksheetFunction.RoundDown(objItem.Value / 1024, 0) & "Mb"
                        Exit For
                End Select
            Next objItem
        Case "FREESTORAGE"
            Set objWMIService = GetObject("winmgmts:\\" & _
            strComputer & "\root\CIMV2")

            Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " & 3 & "")

            For Each objDisk In colDisks
                GetOSInfo = WorksheetFunction.RoundDown(objDisk.FreeSpace / 1024 / 1024, 0) & "Mb," & WorksheetFunction.RoundDown(objDisk.Size / 1024 / 1024, 0) & "Mb"
            Next
    End Select

Exit_GetOSInfo:
    ' Release Memory
    Set objItem = Nothing
    Set colItems = Nothing
    Set objWMIService = Nothing
    Exit Function

Err_GetOSInfo:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ")" & _
    " In procedure GetOSInfo"
    Resume Exit_GetOSInfo

End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SuperLightAuthor Commented:
Hi teylyn,

Solution added!

Thanks

Mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.