c # - Opret et gendannelsespunkt manuelt

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg checkede rundt og brugte endda/tweaked flere løsninger herunder følgende, men jeg fortsætter med at få en af ​​to fejl. Jeg får enten


************** 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:UsersGregSourceReposCheck In ToolCheck In ToolCheck In ToolForm1.cs:line 268
at Check\_In\_Tool.checkInForm.button1\_Click(Object sender, EventArgs e) in C:UsersGregSourceReposCheck In ToolCheck In ToolCheck In ToolForm1.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))


eller



  RPC-serveren er ikke tilgængelig. (Undtagelse fra HRESULT: 0x800706BA)



Koden jeg bruger i øjeblikket er som følger:


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);
}


Rediger: Jeg opdaterede min kode fra err.Message til err.ToString () og fik nogle nye oplysninger. Problemet ligger tilsyneladende inden for denne linje af kode:


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


Nogle ideer?

Bedste reference