Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式创建还原点_C#_.net_Windows_Systemmanagement - Fatal编程技术网

C# 以编程方式创建还原点

C# 以编程方式创建还原点,c#,.net,windows,systemmanagement,C#,.net,Windows,Systemmanagement,我四处查看,甚至利用/调整了几个解决方案,包括以下内容,但我一直收到两个错误中的一个。我要么得到 ************** Exception Text ************** System.Runtime.InteropServices.COMException (0x80070422) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr error

我四处查看,甚至利用/调整了几个解决方案,包括以下内容,但我一直收到两个错误中的一个。我要么得到

************** 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))

RPC服务器不可用。(来自HRESULT的异常:0x800706BA)

我目前使用的代码如下:

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);
}
编辑:我将代码从err.Message更新为err.ToString(),并获得了一些新信息。显然,问题在于这一行代码:

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

有什么想法吗?

你从哪里得到错误,COM异常的
HRESULT
是什么?@IInspectable我的try/catch实际上没有捕获COM异常。它在异常窗口中打开,并显示以下内容:***************************************异常文本***************System.Runtime.InteropServices.COMException(0x80070422)您的捕获是针对特定错误类型的,您是否可以为COMException添加捕获,并查看stacktrace为您提供了什么?@KevinCook我不完全确定您在寻找什么。当我使用justexception时,我在帖子中得到了第一个错误。我能提供更多的细节吗?@KevinCook我错了,我的代码有问题-COMException返回一个空的messagebox。没有文本。