C# 创建还原点 netframework 3.5
C# create restore point netframework 3.5
是否可以在 netframework 3.5 目标中从 C# 创建还原点以及所有需要的任务(启用系统保护、调整 shadowstorage 大小)?
我找到了一些示例,但它们都使用 System.Management.Automation 来执行 netframework 3.5 中不可用的 powshershell 脚本。
我想做的是将整个操作(如果禁用则启用系统还原,调整 shadowstorage 大小并创建还原点)绑定到 gui 内的按钮上。
这是一个使用 WMI 的 winforms 代码,享受:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class CallWMIMethod
{
public new static int Main()
{
try
{
ManagementObject classInstance = new ManagementObject(@"root\DEFAULT", "SystemRestore.ReplaceKeyPropery='ReplaceKeyPropertyValue'", null);
// Obtain [in] parameters for the method
ManagementBaseObject inParams = classInstance.GetMethodParameters("CreateRestorePoint");
// Add the input parameters.
// Execute the method and obtain the return values.
ManagementBaseObject outParams = classInstance.InvokeMethod("CreateRestorePoint", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"));
}
catch (ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
}
}
}
是否可以在 netframework 3.5 目标中从 C# 创建还原点以及所有需要的任务(启用系统保护、调整 shadowstorage 大小)? 我找到了一些示例,但它们都使用 System.Management.Automation 来执行 netframework 3.5 中不可用的 powshershell 脚本。 我想做的是将整个操作(如果禁用则启用系统还原,调整 shadowstorage 大小并创建还原点)绑定到 gui 内的按钮上。
这是一个使用 WMI 的 winforms 代码,享受:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class CallWMIMethod
{
public new static int Main()
{
try
{
ManagementObject classInstance = new ManagementObject(@"root\DEFAULT", "SystemRestore.ReplaceKeyPropery='ReplaceKeyPropertyValue'", null);
// Obtain [in] parameters for the method
ManagementBaseObject inParams = classInstance.GetMethodParameters("CreateRestorePoint");
// Add the input parameters.
// Execute the method and obtain the return values.
ManagementBaseObject outParams = classInstance.InvokeMethod("CreateRestorePoint", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"));
}
catch (ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
}
}
}