Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class CallWMIMethod
Public Overloads Shared Function Main() As Integer
Try
Dim classInstance As New ManagementClass( _
"root\CIMV2", _
"Win32_Share", Nothing)
' Obtain [in] parameters for the method
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("Create")
' Add the input parameters.
inParams("Description") = "partagé par script"
inParams("MaximumAllowed") = 25
inParams("Name") = "PartagéParScript"
inParams("Password") = """"
inParams("Path") = "c:\temp"
inParams("Type") = 0
' Execute the method and obtain the return values.
Dim outParams As ManagementBaseObject = _
classInstance.InvokeMethod("Create", inParams, Nothing)
' List outParams
Console.WriteLine("Out parameters:")
Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"))
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to execute the WMI method: " & err.Message)
End Try
End Function
End Class
End Namespace
Partager