簡體   English   中英

VB.NET GetObject(“ winmgmts,具有后期綁定

[英]VB.NET GetObject("winmgmts with late binding

我正在盡力不要將后期綁定與getObject函數一起使用。 我怎么知道我不會因為只有一堂課而嚴格拒絕考試。

我的問題是我找不到聲明我的會員類型的東西。

         Dim restPoint = GetObject("winmgmts:\\.\root\default:Systemrestore")

    If restPoint IsNot Nothing Then

        If restPoint.CreateRestorePoint("test restore point system", 12, 100) = 0 Then
            MsgBox("Restore Point created successfully")
        Else
            MsgBox("Could not create restore point!")
        End If
    End If

我花了幾個小時嘗試研究msdn createrestorepoint的來源。 我不想直接使用WMI或嚴格禁止使用。

謝謝

我想我現在將使用WMI。 那段代碼清理了。

Imports System.Management

Public Class CreateRestorePoint

''' <summary>
''' Defines the search query for the ManagementScope path.
''' </summary>
Private Const MANAGEMENT_SCOPE As String = "\\localhost\root\default:SystemRestore"

''' <summary>
''' Attempts to create a new restore point using WMI.
''' </summary>
''' <returns>True if the restore point was created, other wise false.</returns>
''' <remarks>
''' Gets the object containing the input parameters to a method, and then fills in the values and passes the object to the InvokeMethod call.
''' </remarks>
Friend Function CreateRestorePoint() As Boolean

    Dim created As Boolean = True

    Using wmiQuery As New ManagementClass(New ManagementPath(MANAGEMENT_SCOPE))

        Dim query = GetParams(wmiQuery)

        Try
            wmiQuery.InvokeMethod("CreateRestorePoint", query, Nothing)
        Catch ex As ManagementException
            created = False
        End Try

    End Using

    Return created

End Function

''' <summary>
''' Sets the ManagementBaseObject parameters.
''' </summary>
''' <param name="wmiQuery"></param>
''' <returns>Returns a ManagementBaseObject representing the list of input parameters for a method.</returns>
''' <remarks>The members of this class enable you to access WMI data using a specific WMI class path.></remarks>
Private Function GetParams(wmiQuery As ManagementClass) As ManagementBaseObject

    Dim query = wmiQuery.GetMethodParameters("CreateRestorePoint")

    query("Description") = "-CautionSparta"
    query("RestorePointType") = 12
    query("EventType") = 100

    Return query

End Function

End Class

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM