问题描述:

I really didn't know what to set the title as. Sorry for being too vague. I have a couple questions specific to my VB Script.

First off, I have a piece that determines how much RAM is installed in my PC. I would like it to output as one amount. Currently, it outputs each slot in my computer. For example...

Capacity:, 1024, Speed:, 1333

Capacity:, 1024, Speed:, 1333

Capacity:, 1024, Speed:, 1333

Capacity:, 1024, Speed:, 1333

I want it to output as one line, combined (in my case, 4 GB). Here is my code:

'Finds the computer's RAM capacity and speed.

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")

For Each objItem in colItems

convertedResult = objItem.Capacity/1048576

MyFile.WriteLine ("Capacity:, " & convertedResult & ", Speed:, " & objItem.Speed)

Next

My next issue is I want to find out what network adapters are in my PC, and their MAC address. I simply want to find the physical LAN adapters and WLAN adapters. I do not want any virtual adapters.

'Finds the computer's network adapters' name and MAC address (this includes virtual adapters).

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")

For Each objItem in colItems

MyFile.WriteLine ("Name:, " & objItem.Name & ", MAC Address:, " & objItem.MACAddress)

Next

网友答案:

For the memory, try this:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")

    dim total

    For Each objItem in colItems    
      convertedResult = objItem.Capacity/1048576
      total = total + convertedResult
    Next


    MyFile.WriteLine ("Capacity:, " & total )
相关阅读:
Top