Skip to content

Create TemplateStaticMethodInvokerVBNet.vb #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Templates/TemplateStaticMethodInvokerVBNet.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Imports System.Management

Module Module1

[WMIMETHODDESC]
Sub Main()

Dim computerName As String = "localhost"
Dim conn As ConnectionOptions = Nothing
Dim scope As ManagementScope
Dim options As ObjectGetOptions
Dim path As ManagementPath
Dim classInstance As ManagementClass
Dim inParams As ManagementBaseObject
Dim outParams As ManagementBaseObject

If Not computerName.Equals("localhost", StringComparison.OrdinalIgnoreCase) Then
conn = New ConnectionOptions With
{
.Username = "",
.Password = "",
.Authority = "ntlmdomain:DOMAIN"
}
End If

Try
scope = New ManagementScope(String.Format("\\{0}\[WMINAMESPACE]", computerName), options:=If(conn IsNot Nothing, conn, Nothing))
scope.Connect()

options = New ObjectGetOptions()
path = New ManagementPath("[WMICLASSNAME]")
classInstance = New ManagementClass(scope, path, options)
inParams = classInstance.GetMethodParameters("[WMIMETHOD]")

[VBNETCODEINPARAMS]
outParams = classInstance.InvokeMethod("[WMIMETHOD]", inParams, options:=Nothing)
[VBNETCODEOUTPARAMS]

Catch ex As Exception
Console.WriteLine(String.Format("Exception: {0} Trace: {1}", ex.Message, ex.StackTrace))

End Try

Console.WriteLine("Press Enter to exit.")
Console.Read()

End Sub

End Module