Several WMI examples (primary) - 2

zhaozj2021-02-16  46

Some examples were collected below;

Get information about local hard drives:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

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

Disk.get ()

Console.WriteLine ("Logical Disk Size IS" Disk ("size"). Tostring "Bytes")

End Sub

End module

Drive Type Disk ("DriveType"):

Value = 2

Value = 3

Value = 4

Value = 5

Value = 6

FLOPPY DISK

Hard Disk

Network drive

CDROM

Ram Disk

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

From the newly launched remote computer: (requires permissions)

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM CO As ConnectionOptions = New ConnectionOptions

Co. HUSERNAME = "admin" 'Login User Name

Co.Password = "12345678" 'Password

DIM ms as system.management.managementscope = new system.management.managementscope ("// 192.168.1.2/root/cimv2", CO)

Dim oq as system.management.ObjectQuery = new system.management.ObjectQuery ("SELECT * WIN32_OPERATISTEM")

DIM MOS as ManagementObjectSearcher = New ManagementObjectSearcher (MS, OQ)

DIM _QUERY As ManagementObjectCollection = Mos.Get ()

Dim Mo as ManagementObject

For Each Mo in _Query

DIM TMP () AS String = {"}

Mo.invokeMethod ("Reboot", TMP)

Console.writeline (mo.to.tostring ())

NEXT

End Sub

End module

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

Create a process:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM processClass As ManagementClassClass = New ManagementClass ("Win32_Process") DIM INPARAMS as ManagementBaseObject = ProcessClass.getMethodparameters ("create")

INPARAMS ("CommandLine") = "Calc.exe"

Dim outparams as managementBaseObject = ProcessClass.InvokeMethod ("Create", INPARAMS, NOTING)

Console.Writeline ("Creation of Calculator Process Returned:" Outparams ("ReturnValue"))

Console.writeline ("Process ID:" & Outparams ("Processid")))))

End Sub

End module

End a process:

Imports system

Imports System.Management

Module Module1

Public SUB

Main

()

DIM service as managementObject = new management ("win32_service =" "Winmgmt" ")

DIM OPTIONS AS INVOKEMETHODOPTIONS = New InvokeMethodOptions

Options.timeout = New TimeSpan (0, 0, 0, 5)

Dim outparams as managementBaseObject = Service.InvokeMethod ("StopService", Nothing, Options

Console.writeLine ("Status:" & Outparams ("ReturnValue"))

End Sub

End module

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

New Post(0)