【问题标题】:VB.NET GetObject("winmgmts with late bindingVB.NET GetObject("带有后期绑定的 winmgmts
【发布时间】:2015-03-19 20:02:19
【问题描述】:

我正在尽力不使用 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 或保持严格关闭。

谢谢

【问题讨论】:

  • 你问的是restpoint吗?
  • 抱歉,我错过了“我不想使用 WMI”,但为了记录,Strict Off is 编码错误。没有什么是你不能用它来做的,你不能用它来做。如果你不同意,我邀请你给我一些链接来证明我错了
  • jmcilhinney,可能是周围最好的 vbcoder 之一。上帝的 MVP 知道多少年 vbforums.com/… Joacim Andersson 是 vbofurms 的所有者 vbforums.com/… 在一个项目中严格关闭 ONE 类并不错。

标签: vb.net wmi


【解决方案1】:

我想我现在会选择 WMI。那个 sn-p 清理干净了。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多