trparky
Member
- Joined
- Jun 18, 2011
- Messages
- 7
- Location
- Cleveland, Ohio, United States
- Programming Experience
- Beginner
VB.NET:
Imports System.Management
Imports System.Runtime.InteropServices
Module systemRestore
Function createRestorePoint(strDescription As String, rt As RestoreType, ByRef lSeqNum As Long) As Integer
Try
Dim managementScopeObject As New ManagementScope("\\localhost\root\default")
Dim managementPathObject As New ManagementPath("SystemRestore")
Dim managementObjectOptions As New ObjectGetOptions()
Dim managementClassObject As New ManagementClass(managementScopeObject, managementPathObject, managementObjectOptions)
Dim managementBaseObjectParameters As ManagementBaseObject = managementClassObject.GetMethodParameters("CreateRestorePoint")
managementBaseObjectParameters("Description") = strDescription
managementBaseObjectParameters("RestorePointType") = rt
managementBaseObjectParameters("EventType") = 100
Dim oOutParams As ManagementBaseObject = managementClassObject.InvokeMethod("CreateRestorePoint", managementBaseObjectParameters, Nothing)
Return oOutParams("ReturnValue")
Catch ex As Exception
MsgBox(ex.Message)
Return 0
End Try
End Function
End Module
I have a number of people saying that they are receiving this particular crash.
Exception Type: System.Runtime.InteropServices.COMException The exception occurred at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options) at My_Program.createRestorePoint(String strDescription, RestoreType rt, Int64& lSeqNum)
I have been unable to narrow down why this crash is occurring. The code works exactly as intended with absolutely no issues on my desktop, notebook, and several instances of Windows (XP, Vista, 7, 8, and 8.1 Update 1) that I have installed in VirtualBox VMs. I'm tearing my hair out here because I have no earthly idea why this is happening. If it were happening on my own machines I'd be able to track down where the issue is but I can't reproduce this crash on my machines or in my VMs.
What am I doing wrong here?