Several WMI examples (primary) - 3

zhaozj2021-02-16  51

Get the directory of the remote machine and the file information:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM Disk as managementObject = New managementObject ("Win32_LogicalDisk.DeviceId =" "C:" "")

Disk.get ()

Console.writeline ("Bytes):" & Disk ("size"))

End Sub

End module

-------------------------------------------------- -------------------------------------

Get physical memory size:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM strComputer = "computername" 'computer name

DIM WBEMSERVICES, WBEMOBJECTSET, WBEMOBJECT

WbemServices = getObject ("WinMgmts: //" & struct

WBemObjectSet = WbemServices.instanceSof ("Win32_LogicalMemoryConfiguration")

For Each WBemObject in WbemObjectset

Console.writeline ("Physical Memory Size (KB):" & WbemObject.totalphysicalMemory)

NEXT

End Sub

End module

-------------------------------------------------- -------------------------------------

Get available memory sizes:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM STRComputer As string = ".", I, intValue as integer

Dim Colitems, Objwmiservice, Objitem

Objwmiservice = getObject ("WinMgmts: //" & strComputer & "/ root / cimv2")

'Repeating 20 reviews

For i = 1 to 20

'Generate memory snapshot

Colitems = objwmiservice.execQuery ("SELECT * WIN32_PERFRAWDATA_PERFOS_MEMORY")

For Each Objitem in Colitems

INTVALUE = Objitem.availablembytes

Console.writeline ("Available Memory Size (MB):" & INTVALUE)

'Delay 5 seconds

Threading.thread.sleep (5000)

NEXT

NEXT

End Sub

End module

-------------------------------------------------- -------------------------------------- Get service name:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM strComputer = "computername"

DIM WBEMSERVICES, WBEMOBJECTSET, WBEMOBJECT

WbemServices = getObject ("WinMgmts: //" & struct

WBemObjectSet = WBEMSERVICES.INSTANCESOF ("Win32_Service")

For Each WBemObject in WbemObjectset

Console.WriteLine ("Service Name:" & wbemObject.displayName)

Console.writeline ("Current Status:" & WbemObject.State)

Console.writeline ("Start Mode:" & WbemObject.Startmode)

NEXT

End Sub

End module

转载请注明原文地址:https://www.9cbs.com/read-23136.html

New Post(0)