本文整理匯總了C#中System.Management.ManagementClass.GetMethodParameters方法的典型用法代碼示例。如果您正苦於以下問題:C# ManagementClass.GetMethodParameters方法的具體用法?C# ManagementClass.GetMethodParameters怎麽用?C# ManagementClass.GetMethodParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Management.ManagementClass
的用法示例。
在下文中一共展示了ManagementClass.GetMethodParameters方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: buttonSystemRestore_Click
//Create a system restore point using WMI. Should work in XP, VIsta and 7
private void buttonSystemRestore_Click(object sender, EventArgs e)
{
ManagementScope oScope = new ManagementScope("\\\\localhost\\root\\default");
ManagementPath oPath = new ManagementPath("SystemRestore");
ObjectGetOptions oGetOp = new ObjectGetOptions();
ManagementClass oProcess = new ManagementClass(oScope, oPath, oGetOp);
ManagementBaseObject oInParams = oProcess.GetMethodParameters("CreateRestorePoint");
oInParams["Description"] = "Nvidia PowerMizer Manager";
oInParams["RestorePointType"] = 10;
oInParams["EventType"] = 100;
this.buttonOK.Enabled = false;
this.buttonCancel.Enabled = false;
this.buttonSystemRestore.Enabled = false;
this.labelDis.Text = "Creating System Restore Point. Please wait...";
ManagementBaseObject oOutParams = oProcess.InvokeMethod("CreateRestorePoint", oInParams, null);
this.buttonOK.Enabled = true;
this.buttonCancel.Enabled = true;
this.buttonSystemRestore.Enabled = true;
this.labelDis.Text = text;
}
示例2: Run
//private char NULL_VALUE = char(0);
public static ProcessReturnCode Run(string machineName, string commandLine, string args, string currentDirectory)
{
var connOptions = new ConnectionOptions
{
EnablePrivileges = true
};
var scope = new ManagementScope(@"\\{0}\root\cimv2".FormatWith(machineName), connOptions);
scope.Connect();
var managementPath = new ManagementPath(CLASSNAME);
using (var processClass = new ManagementClass(scope, managementPath, new ObjectGetOptions()))
{
var inParams = processClass.GetMethodParameters("Create");
commandLine = System.IO.Path.Combine(currentDirectory, commandLine);
inParams["CommandLine"] = "{0} {1}".FormatWith(commandLine, args);
var outParams = processClass.InvokeMethod("Create", inParams, null);
var rtn = Convert.ToUInt32(outParams["returnValue"]);
var pid = Convert.ToUInt32(outParams["processId"]);
if (pid != 0)
{
WaitForPidToDie(machineName, pid);
}
return (ProcessReturnCode)rtn;
}
}
示例3: CreateShare
/// <summary>
/// Creates the share.
/// </summary>
/// <param name="FolderName">Name of the folder.</param>
/// <param name="ShareName">Name of the share.</param>
/// <param name="Description">The description.</param>
/// <exception cref="System.Exception">Unable to share directory.</exception>
public static void CreateShare(string FolderName, string ShareName, string Description )
{
var RootPath = HostingEnvironment.ApplicationPhysicalPath;
// Does folder exist?
var StoreLocation = CreateFolder(FolderName, RootPath);
ManagementClass managementClass = new ManagementClass("Win32_Share");
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
// Set the input parameters
inParams["Description"] = Description;
inParams["Name"] = ShareName;
inParams["Path"] = StoreLocation;
inParams["Type"] = ManagementType.DiskDrive; // Disk Drive
//Another Type:
// DISK_DRIVE = 0x0
// PRINT_QUEUE = 0x1
// DEVICE = 0x2
// IPC = 0x3
// DISK_DRIVE_ADMIN = 0x80000000
// PRINT_QUEUE_ADMIN = 0x80000001
// DEVICE_ADMIN = 0x80000002
// IPC_ADMIN = 0x8000003
//inParams["MaximumAllowed"] = int maxConnectionsNum;
// Invoke the method on the ManagementClass object
outParams = managementClass.InvokeMethod("Create", inParams, null);
// Check to see if the method invocation was successful
if ((uint) (outParams.Properties["ReturnValue"].Value) != 0)
{
throw new Exception("Unable to share directory.");
}
}
示例4: Bob
public void Bob()
{
var connOptions = new ConnectionOptions
{
EnablePrivileges = true,
//Username = "username",
//Password = "password"
};
string server = "SrvTestWeb01";
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", server), connOptions);
manScope.Connect();
var managementPath = new ManagementPath("Win32_Process");
var processClass = new ManagementClass(manScope, managementPath, new ObjectGetOptions());
var inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = @"C:\Temp\dropkick.remote\dropkick.remote.exe create_queue msmq://localhost/dk_test";
var outParams = processClass.InvokeMethod("Create", inParams, null);
var rtn = System.Convert.ToUInt32(outParams["returnValue"]);
var processID = System.Convert.ToUInt32(outParams["processId"]);
}
示例5: Shutdown
public static void Shutdown(string mode)
{
if (mode == "WMI")
{
ManagementBaseObject mboShutdown = null;
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
mcWin32.Get();
// Get Security Privilages
mcWin32.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");
//Option Flags
mboShutdownParams["Flags"] = "1";
mboShutdownParams["Reserved"] = "0";
foreach (ManagementObject manObj in mcWin32.GetInstances())
{
mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
}
}
else if (mode == "Core")
{
Process.Start("shutdown", "/s /t 0");
}
}
示例6: Shutdown
public void Shutdown()
{
ManagementBaseObject mboShutdown = null;
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
mcWin32.Get();
/* You can't shutdown without security privileges */
mcWin32.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams =
mcWin32.GetMethodParameters("Win32Shutdown");
/* 0 = Log off the network.
* 1 = Shut down the system.
* 2 = Perform a full reboot of the system.
* 4 = Force any applications to quit instead of prompting the user to close them.
* 8 = Shut down the system and, if possible, turn the computer off. */
/* Flag 1 means we want to shut down the system. Use "2" to reboot. */
mboShutdownParams["Flags"] = "1";
mboShutdownParams["Reserved"] = "0";
foreach (ManagementObject manObj in mcWin32.GetInstances())
{
mboShutdown = manObj.InvokeMethod("Win32Shutdown",
mboShutdownParams, null);
}
}
示例7: AddARecord
public void AddARecord(string hostName, string zone, string iPAddress, string dnsServerName)
{
/*ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
connOptions.Username = "nwtraders\administrator";
connOptions.Password = "Password01";
*/
ManagementScope scope =
new ManagementScope(@"\\" + dnsServerName + "\\root\\MicrosoftDNS"); //,connOptions);
scope.Connect();
ManagementClass wmiClass =
new ManagementClass(scope,
new ManagementPath("MicrosoftDNS_AType"),
null);
ManagementBaseObject inParams =
wmiClass.GetMethodParameters("CreateInstanceFromPropertyData");
inParams["DnsServerName"] = dnsServerName;
inParams["ContainerName"] = zone;
inParams["OwnerName"] = hostName + "." + zone;
inParams["IPAddress"] = iPAddress;
wmiClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null);
}
示例8: CreateShare
/// <summary>
/// Creates the share.
/// </summary>
/// <param name="shareName">Name of the share.</param>
/// <param name="folderPath">The folder path.</param>
/// <returns>WindwsShare instance.</returns>
public static WindowsShare CreateShare(string shareName, string folderPath)
{
ManagementClass shareClass = null;
ManagementClass sd = null;
ManagementBaseObject inParams = null;
ManagementBaseObject outParams = null;
try
{
sd = new ManagementClass(new ManagementPath("Win32_SecurityDescriptor"), null);
sd["ControlFlags"] = 0x4;
sd["DACL"] = new ManagementBaseObject[] { };
shareClass = new ManagementClass("Win32_Share");
inParams = shareClass.GetMethodParameters("Create");
inParams["Name"] = shareName;
inParams["Path"] = new DirectoryInfo(folderPath).FullName;
//// inParams["Description"] = description;
inParams["Type"] = 0x0; // Type of Disk Drive
inParams["Access"] = sd;
outParams = shareClass.InvokeMethod("Create", inParams, null);
if ((uint)outParams["ReturnValue"] != 0)
{
throw new WindowsShareException("Unable to create share. Win32_Share.Create Error Code: " + outParams["ReturnValue"]);
}
}
catch (Exception ex)
{
throw new WindowsShareException("Unable to create share", ex);
}
finally
{
if (shareClass != null)
{
shareClass.Dispose();
}
if (inParams != null)
{
inParams.Dispose();
}
if (outParams != null)
{
outParams.Dispose();
}
if (sd != null)
{
sd.Dispose();
}
}
return new WindowsShare(shareName);
}
示例9: StartProcess
public static string StartProcess(string machineName, string processPath)
{
ManagementClass processTask = new ManagementClass(@"\\" + machineName + @"\root\CIMV2",
"Win32_Process", null);
ManagementBaseObject methodParams = processTask.GetMethodParameters("Create");
methodParams["CommandLine"] = processPath;
ManagementBaseObject exitCode = processTask.InvokeMethod("Create", methodParams, null);
return ProcessMethod.TranslateProcessStartExitCode(exitCode["ReturnValue"].ToString());
}
示例10: Execute
public override void Execute(object context = null)
{
ActionsHomeModel pc = context as ActionsHomeModel;
//Can only be processed if the machine is online...
if (pc.Status == ComputerStates.Online || pc.Status == ComputerStates.LoggedOn)
{
ManagementScope oMs = ConnectToClient(pc.Name);
if (oMs != null)
{
this.DeleteQueryData(oMs, @"root\ccm\Policy", "SELECT * FROM CCM_SoftwareDistribution");
this.DeleteQueryData(oMs, @"root\ccm\Policy", "SELECT * FROM CCM_Scheduler_ScheduledMessage");
this.DeleteQueryData(oMs, @"root\ccm\Scheduler", "SELECT * FROM CCM_Scheduler_History");
//oMs.Path.NamespacePath = @"ROOT\CCM";
ManagementClass oClass = new ManagementClass(oMs, new ManagementPath("SMS_Client"), null);
oClass.Get();
ManagementBaseObject inParams = oClass.GetMethodParameters("ResetPolicy");
inParams["uFlags"] = 1;
oClass.InvokeMethod("ResetPolicy", inParams, new InvokeMethodOptions());
ManagementBaseObject newParams = oClass.GetMethodParameters("RequestMachinePolicy");
oClass.InvokeMethod("RequestMachinePolicy", newParams, new InvokeMethodOptions());
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
this.State = RemoteActionState.Completed;
}), null);
}
else
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
this.State = RemoteActionState.Error;
}), null);
}
}
else
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
this.State = RemoteActionState.Pending;
}), null);
}
}
示例11: CreateKey
public static void CreateKey(ManagementScope connectionScope,
baseKey BaseKey,
string key)
{
ManagementClass registryTask = new ManagementClass(connectionScope,
new ManagementPath("DEFAULT:StdRegProv"), new ObjectGetOptions());
ManagementBaseObject methodParams = registryTask.GetMethodParameters("CreateKey");
methodParams["hDefKey"] = BaseKey;
methodParams["sSubKeyName"] = key;
ManagementBaseObject exitCode = registryTask.InvokeMethod("CreateKey",
methodParams, null);
}
示例12: ExitWindows
public static void ExitWindows(uint uFlags, uint dwReason)
{
ManagementBaseObject outParams = null;
ManagementClass os = new ManagementClass("Win32_OperatingSystem");
os.Get();
os.Scope.Options.EnablePrivileges = true; // enables required security privilege.
ManagementBaseObject inParams = os.GetMethodParameters("Win32Shutdown");
inParams["Flags"] = uFlags.ToString();
inParams["Reserved"] = "0";
foreach (ManagementObject mo in os.GetInstances())
{
outParams = mo.InvokeMethod("Win32Shutdown",inParams, null);
}
}
示例13: MainWindow_Closed
private void MainWindow_Closed(object sender, EventArgs e)
{
if (MessageBox.Show("You must restart your computer to apply these changes.\nRestart now?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) {
ManagementClass os = new ManagementClass("Win32_OperatingSystem");
os.Get();
os.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams = os.GetMethodParameters("Win32Shutdown");
mboShutdownParams["Flags"] = "6";
mboShutdownParams["Reserved"] = "0";
ManagementBaseObject obj;
foreach (ManagementObject instance in os.GetInstances())
obj = instance.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
}
}
示例14: Shutdown
/// <summary>
/// Shutdown the computer
/// </summary>
public static void Shutdown()
{
ManagementClass managementClass = new ManagementClass("Win32_OperatingSystem");
managementClass.Get();
managementClass.Scope.Options.EnablePrivileges = true;
ManagementBaseObject methodParameters = managementClass.GetMethodParameters("Win32Shutdown");
methodParameters["Flags"] = "1";
methodParameters["Reserved"] = "0";
foreach (ManagementObject managementObject in managementClass.GetInstances())
{
managementObject.InvokeMethod("Win32Shutdown", methodParameters, null);
}
}
示例15: RunCommand
public ManagementBaseObject RunCommand(Dictionary<string, string> inArgs)
{
// WMI: Use Win32_Process in root\cimv2 namespace.
var processClass = new ManagementClass(
new ManagementScope(String.Format(@"\\{0}\root\cimv2", this.hostName), this.connectionOptions),
new ManagementPath("Win32_Process"),
new ObjectGetOptions());
ManagementBaseObject parameters = processClass.GetMethodParameters("Create");
foreach (var item in inArgs)
{
parameters[item.Key] = item.Value;
}
return processClass.InvokeMethod("Create", parameters, null);
}