0

I checked around and even utilized/tweaked several solutions including the following, but I keep getting one of two errors. I either get

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80070422)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at Check_In_Tool.checkInForm.CreateRestorePoint() in C:\Users\Greg\Source\Repos\Check In Tool\Check In Tool\Check In Tool\Form1.cs:line 268
at Check_In_Tool.checkInForm.button1_Click(Object sender, EventArgs e) in C:\Users\Greg\Source\Repos\Check In Tool\Check In Tool\Check In Tool\Form1.cs:line 64
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam))

or

The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

The code I am using currently is as follows:

try
{
    // select local computer
    ManagementScope ManScope = new ManagementScope("\\\\localhost\\root\\DEFAULT");
    // create system restore point
    ManagementPath ManPath = new ManagementPath("SystemRestore");
    // select default options
    ObjectGetOptions ManOptions = new ObjectGetOptions();
    // create management class with previous options
    ManagementClass ManClass = new ManagementClass(ManScope, ManPath, ManOptions);
    // load function parameters
    ManagementBaseObject ManBaseObject = ManClass.GetMethodParameters("CreateRestorePoint");
    // description
    ManBaseObject["Description"] = "Check-In Tool Restore Point";
    // type of the restore point
    ManBaseObject["RestorePointType"] = 0;
    // type of the event
    ManBaseObject["EventType"] = 100;

    ManagementBaseObject OutParam = ManClass.InvokeMethod("CreateRestorePoint", ManBaseObject, null);

    restLabel.Text = "Restore Point Set: Yes";
}
catch (ManagementException err)
{
    restLabel.Text = "Restore Point Set: No - Error";
    MessageBox.Show(err.Message);
}

Edit: I updated my code from err.Message to err.ToString() and got some new information. The issue, apparently, lies within this line of code:

ManagementBaseObject OutParam = ManClass.InvokeMethod("CreateRestorePoint", ManBaseObject, null);

Any ideas?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Where do you get the errors, and what is the `HRESULT` of the COM exception? – IInspectable Feb 17 '17 at 20:02
  • @IInspectable the COM exception isn't actually caught by my try/catch. It opens in the Exception window with the following: ************** Exception Text ************** System.Runtime.InteropServices.COMException (0x80070422) – Greg Davis Feb 17 '17 at 20:14
  • your catch is for a specific error type, can you add a catch for comexception and see what the stacktrace gives you? – Kevin Cook Feb 17 '17 at 20:36
  • @KevinCook I am not entirely certain what you're looking for. When I use just Exception I get the first error in my post. Are there more details I can give? – Greg Davis Feb 17 '17 at 20:47
  • @KevinCook My mistake, I had an issue with my code - the COMException returns an empty messagebox. No text. – Greg Davis Feb 17 '17 at 21:12
  • that error code 0x80070422 is ERROR_SERVICE_DISABLED. Did the user disable the Windows feature that exposes the API? – Sheng Jiang 蒋晟 Feb 17 '17 at 21:46
  • @ShengJiang this is on my personal device and I've not knowingly disabled any of the defaults. Any idea where I'd check for that? – Greg Davis Feb 19 '17 at 02:59
  • @ShengJiang蒋晟 I updated my post, would you mind taking another look and seeing if I am missing something? I've got a default setup on my device. Additionally, I've had this code work on other's devices, but I'd say less than 50%. Any clues? – Greg Davis Feb 19 '17 at 21:47

0 Answers0