-
-
Save Toyz/8a95af036927d83d56ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Management; | |
using System.Windows.Forms; | |
namespace WMISample | |
{ | |
public class CallWMIMethod | |
{ | |
public static void 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. | |
inParams["Description"] = "My test restore point"; | |
inParams["EventType"] = 100; | |
inParams["RestorePointType"] = 0; | |
// Execute the method and obtain the return values. | |
ManagementBaseObject outParams = | |
classInstance.InvokeMethod("CreateRestorePoint", inParams, null); | |
// List outParams | |
Console.WriteLine("Out parameters:"); | |
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]); | |
} | |
catch(ManagementException err) | |
{ | |
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment