CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2014
    Posts
    1

    WMI SystemRestore InteropServices.COMException Crash. What's wrong?

    Code:
    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?

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Resolved Re: WMI SystemRestore InteropServices.COMException Crash. What's wrong?

    This could really be anywhere in that code, but based on your testing I'm going to say that it's a x86/x64 issue.

    Try changing the build platform to x86.

    Right click on the solution, select configuration manager. Change the Platform to x86.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured