Skip to content

Instantly share code, notes, and snippets.

@Toyz
Created August 9, 2015 03:17
Show Gist options
  • Save Toyz/8a95af036927d83d56ce to your computer and use it in GitHub Desktop.
Save Toyz/8a95af036927d83d56ce to your computer and use it in GitHub Desktop.
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