我对我的VB脚本有几个问题

时间:2013-12-22 03:13:54

标签: vbscript

我真的不知道该怎么设置标题。抱歉太模糊了。我有几个特定于我的VB脚本的问题。

首先,我有一块确定我的电脑中安装了多少RAM。我希望它输出一个数量。目前,它输出我的计算机中的每个插槽。例如......

Capacity:, 1024, Speed:, 1333
Capacity:, 1024, Speed:, 1333
Capacity:, 1024, Speed:, 1333
Capacity:, 1024, Speed:, 1333

我希望它输出为一行,合并(在我的情况下,4 GB)。这是我的代码:

'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

我的下一个问题是我想知道我的电脑中有哪些网络适配器及其MAC地址。我只是想找到物理LAN适配器和WLAN适配器。我不想要任何虚拟适配器。

'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

1 个答案:

答案 0 :(得分:0)

对于记忆,试试这个:

    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 )