本文整理汇总了C#中System.Management.ManagementObject.GetMethodParameters方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObject.GetMethodParameters方法的具体用法?C# ManagementObject.GetMethodParameters怎么用?C# ManagementObject.GetMethodParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementObject
的用法示例。
在下文中一共展示了ManagementObject.GetMethodParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetServiceDesktopInsteract
/// <summary>
/// 设置服务与桌面交互,在serviceInstaller1的AfterInstall事件中使用
/// </summary>
/// <param name="serviceName">服务名称</param>
private void SetServiceDesktopInsteract(string serviceName)
{
ManagementObject wmiService = new ManagementObject(string.Format("Win32_Service.Name='{0}'", serviceName));
ManagementBaseObject changeMethod = wmiService.GetMethodParameters("Change");
changeMethod["DesktopInteract"] = true;
ManagementBaseObject utParam = wmiService.InvokeMethod("Change", changeMethod,null);
}
示例2: Install
public override void Install(System.Collections.IDictionary savedState)
{
try
{
base.Install(savedState);
// Turn on "Allow service to interact with desktop".
// (Note: A published technique to do this by setting a bit in the service's Type registry value (0x100) does not turn this on, so do as follows.)
// This will let the NotifyIcon appear in the sys tray (with balloon at start-up), but not its context menu.
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope(@"root\CIMv2", options); // Common Information Model, version 2.
ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + this.serviceInstaller.ServiceName + "'");
ManagementBaseObject inParameters = wmiService.GetMethodParameters("Change");
inParameters["DesktopInteract"] = true;
ManagementBaseObject outParameters = wmiService.InvokeMethod("Change", inParameters, null);
}
catch (Exception e)
{
string licenseKey = "";
string licenseName = "";
try
{
licenseKey = Properties.Settings.Default.LicenseKey;
licenseName = Properties.Settings.Default.LicenseName;
}
catch { }
Service.Services.LoggingService.AddLogEntry(WOSI.CallButler.ManagementInterface.LogLevel.ErrorsOnly, Utils.ErrorUtils.FormatErrorString(e), true);
CallButler.ExceptionManagement.ErrorCaptureUtils.SendError(e, licenseKey, licenseName, "");
}
}
示例3: SetHostname
public string SetHostname(string hostname)
{
var oldName = Environment.MachineName;
_logger.Log("Old host name: " + oldName);
_logger.Log("New host name: " + hostname);
if (string.IsNullOrEmpty(hostname) || oldName.Equals(hostname, StringComparison.InvariantCultureIgnoreCase))
return 0.ToString();
using (var cs = new ManagementObject(@"Win32_Computersystem.Name='" + oldName + "'"))
{
cs.Get();
var inParams = cs.GetMethodParameters("Rename");
inParams.SetPropertyValue("Name", hostname);
var methodOptions = new InvokeMethodOptions(null, TimeSpan.MaxValue);
var outParams = cs.InvokeMethod("Rename", inParams, methodOptions);
if (outParams == null)
return 1.ToString();
var renameResult = Convert.ToString(outParams.Properties["ReturnValue"].Value);
//Restart in 10 secs because we want finish current execution and write response back to Xenstore.
if ("0".Equals(renameResult))
Process.Start(@"shutdown.exe", @"/r /t 10 /f /d p:2:4");
return renameResult;
}
}
示例4: OnCommitted
protected override void OnCommitted(IDictionary savedState)
{
base.OnCommitted (savedState);
// Setting the "Allow Interact with Desktop" option for this service.
ConnectionOptions connOpt = new ConnectionOptions();
connOpt.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new ManagementScope(@"root\CIMv2", connOpt);
mgmtScope.Connect();
ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + ReflectorMgr.ReflectorServiceName + "'");
ManagementBaseObject inParam = wmiService.GetMethodParameters("Change");
inParam["DesktopInteract"] = true;
ManagementBaseObject outParam = wmiService.InvokeMethod("Change", inParam, null);
#region Start the reflector service immediately
try
{
ServiceController sc = new ServiceController("ConferenceXP Reflector Service");
sc.Start();
}
catch (Exception ex)
{
// Don't except - that would cause a rollback. Instead, just tell the user.
RtlAwareMessageBox.Show(null, string.Format(CultureInfo.CurrentCulture, Strings.ServiceStartFailureText,
ex.ToString()), Strings.ServiceStartFailureTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
}
#endregion
}
示例5: Win32_SharesSearcher
private static void Win32_SharesSearcher()
{
SelectQuery query = new SelectQuery("select * from Win32_Share where Name=\"" + sharename + "\"");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
{
foreach (ManagementObject mo in searcher.Get())
{
foreach (PropertyData prop in mo.Properties)
{
form.textBox1.AppendText(prop.Name + " = " + mo[prop.Name] + Environment.NewLine); }
//form.textBox1.AppendText(string.Format("Win32ShareName: {0} Description {1} Path {2} ", mo.Properties["Name"].Value, mo.Properties["Description"].Value, mo.Properties["Path"].Value) + Environment.NewLine);
}
}
ManagementObject winShareP = new ManagementObject("root\\CIMV2", "Win32_Share.Name=\"" + sharename + "\"", null);
ManagementBaseObject outParams = winShareP.InvokeMethod("GetAccessMask", null, null);
form.textBox1.AppendText(String.Format("access Mask = {0:x}", outParams["ReturnValue"]) + Environment.NewLine);
ManagementBaseObject inParams = winShareP.GetMethodParameters("SetShareInfo");
form.textBox1.AppendText("SetShareInfor in parameters" + Environment.NewLine);
foreach (PropertyData prop in inParams.Properties)
{
form.textBox1.AppendText(String.Format("PROP = {0}, TYPE = {1} ", prop.Name, prop.Type.ToString()) + Environment.NewLine);
}
Object access = inParams.GetPropertyValue("Access");
//Stopped development here because ShareAFolder project exists. The rest of the development is there
//Maybe should copy Sahare a Folder content to here at some point
}
示例6: ChangeServiceStartMode
/// <summary>
/// </summary>
/// <param name="objz"></param>
/// <param name="cmdTag"></param>
/// <returns></returns>
public static bool ChangeServiceStartMode(WmiServiceObj objz, string cmdTag)
{
bool bRel;
var sc = new ServiceController(objz.Name);
string startupType = "";
var myPath = new ManagementPath
{
Server = Environment.MachineName,
NamespacePath = @"root\CIMV2",
RelativePath = string.Format("Win32_Service.Name='{0}'", sc.ServiceName)
};
switch (cmdTag)
{
case "41":
startupType = "Manual";
break;
case "42":
startupType = "Auto";
break;
case "43":
startupType = "Disabled";
break;
}
using (var service = new ManagementObject(myPath))
{
ManagementBaseObject inputArgs = service.GetMethodParameters("ChangeStartMode");
inputArgs["startmode"] = startupType;
service.InvokeMethod("ChangeStartMode", inputArgs, null);
bRel = true;
}
sc.Refresh();
return bRel;
}
示例7: SetNetCfg
public void SetNetCfg(string strIP, string strSubmask, string strGateway, string strDNS1, string strDNS2)
{
// 建立 ManagementObject 物件 ( Scope , Path , options )
objCls = new ManagementObject(strNS, strCls + ".INDEX=" + strIndex, null);
ManagementBaseObject objInPara; // 宣告管理物件類別的基本類別
objInPara = objCls.GetMethodParameters("EnableStatic");
objInPara["IPAddress"] = new string[] { strIP }; // 設定 "IP" 屬性
objInPara["SubnetMask"] = new string[] { strSubmask }; // 設定 "子網路遮罩" 屬性
objCls.InvokeMethod("EnableStatic", objInPara, null);
objInPara = objCls.GetMethodParameters("SetGateways");
objInPara["DefaultIPGateway"] = new string[] { strGateway }; // 設定 "Gateway" 屬性
objCls.InvokeMethod("SetGateways", objInPara, null);
objInPara = objCls.GetMethodParameters("SetDNSServerSearchOrder");
objInPara["DNSServerSearchOrder"] = new string[] { strDNS1, strDNS2 }; // 設定 "DNS" 屬性
objCls.InvokeMethod("SetDNSServerSearchOrder", objInPara, null);
// GetMethodParameters 方法 : 用來取得 SetDNSServerSearchOrder 參數清單。
// InvokeMethod 方法 : 在物件上叫用方法。
}
示例8: SetServiceDesktopInsteract
private void SetServiceDesktopInsteract(string serviceName) {
ConnectionOptions coOptions = new ConnectionOptions();
coOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
mgmtScope.Connect();
ManagementObject wmiService = new ManagementObject(string.Format("Win32_Service.Name='{0}'", serviceName));
ManagementBaseObject changeMethod = wmiService.GetMethodParameters("Change");
changeMethod["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", changeMethod, null);
}
示例9: serviceInstaller1_Committed
private void serviceInstaller1_Committed(object sender, InstallEventArgs e)
{
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope(@"root\CIMV2", options);
scope.Connect();
ManagementObject wmi = new ManagementObject("Win32_Service.Name='" + serviceInstaller1.ServiceName + "'");
ManagementBaseObject inParam = wmi.GetMethodParameters("Change");
inParam["DesktopInteract"] = true;
ManagementBaseObject outParam = wmi.InvokeMethod("Change", inParam, null);
}
示例10: button2_Click
private void button2_Click(object sender, EventArgs e)
{
string AccountName = textBox1.Text,
newNameForAccount = textBox2.Text;
ManagementObject theInstance = new ManagementObject("root\\CIMv2", "Win32_UserAccount.Domain='" + Environment.MachineName + "',Name='" + AccountName + "'", null);
ManagementBaseObject inputParams = theInstance.GetMethodParameters("Rename");
inputParams.SetPropertyValue("Name", newNameForAccount);
ManagementBaseObject outParams = theInstance.InvokeMethod("Rename", inputParams, null);
button2.Hide();
}
示例11: SetComputerName
public static uint SetComputerName(String Name)
{
uint ret;
ManagementObject ob = new ManagementObject();
using (ManagementObject wmiObject = new ManagementObject(new ManagementPath(String.Format("Win32_ComputerSystem.Name='{0}'", System.Environment.MachineName))))
{
ManagementBaseObject inputArgs = wmiObject.GetMethodParameters("Rename");
inputArgs["Name"] = Name;
ManagementBaseObject outParams = wmiObject.InvokeMethod("Rename", inputArgs, null);
ret = (uint)(outParams.Properties["ReturnValue"].Value);
}
return ret;
}
示例12: CreateWebSite
public IisWebSite CreateWebSite(string serverComment, IEnumerable<IisWebSiteBindingDetails> bindings, string documentRoot)
{
var iis = new ManagementObject(scope, new ManagementPath("IIsWebService='W3SVC'"), null);
ManagementBaseObject createNewSiteArgs = iis.GetMethodParameters("CreateNewSite");
createNewSiteArgs["ServerComment"] = serverComment;
createNewSiteArgs["ServerBindings"] = bindings.Select(b => CreateBinding(b)).ToArray();
createNewSiteArgs["PathOfRootVirtualDir"] = documentRoot;
var result = iis.InvokeMethod("CreateNewSite", createNewSiteArgs, null);
var id = (string) result["ReturnValue"];
return new IisWebSite(scope, id);
}
示例13: SetBrightness
public static void SetBrightness(int value)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM WmiMonitorBrightness");
string instance = "";
foreach (ManagementObject queryObj in searcher.Get())
{
instance = queryObj.GetPropertyValue("InstanceName").ToString();
}
ManagementObject classInstance = new ManagementObject(@"root\WMI", @"WmiMonitorBrightnessMethods.InstanceName='" + instance + "'", null);
ManagementBaseObject inParams = classInstance.GetMethodParameters("WmiSetBrightness");
inParams["Brightness"] = value;
inParams["Timeout"] = 5000;
ManagementBaseObject outParams = classInstance.InvokeMethod("WmiSetBrightness", inParams, null);
}
示例14: addToDomain
// add pc to domain
public static bool addToDomain(string userName, string password, string domain)
{
using (ManagementObject wmiObject = new ManagementObject(new ManagementPath("Win32_ComputerSystem.Name='" + System.Environment.MachineName + "'")))
{
try
{
ManagementBaseObject inParams = wmiObject.GetMethodParameters("JoinDomainorWorkgroup");
inParams["Name"] = domain;
inParams["Password"] = password;
inParams["UserName"] = userName;
inParams["FJoinOptions"] = 3;
ManagementBaseObject outParams = wmiObject.InvokeMethod("JoinDomainOrWorkgroup", inParams, null);
if (!outParams["ReturnValue"].ToString().Equals("0")) return false;
return true;
}
catch
{
return false;
}
}
}
示例15: RestartProcess
/// <summary>
/// This will restart the Pocess
/// </summary>
/// <returns>This will return True if the Process is successfully restarted. If the Process isn't running, or if there was an error in restarting it then it will return False.</returns>
public static bool RestartProcess(int PID)
{
string ProcessName = "";
try
{
ManagementObject classInstance = new ManagementObject("root\\CIMV2", "Win32_Process.Handle='"+PID+"'", null);
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT Name FROM Win32_Process WHERE ProcessId =" + PID + @"");
foreach (ManagementObject queryObj in searcher.Get())
{
ProcessName = queryObj["Name"].ToString().Trim();
}
// Obtain in-parameters for the method
ManagementBaseObject inParams = classInstance.GetMethodParameters("Terminate");
// Add the input parameters.
// Execute the method and obtain the return values.
ManagementBaseObject outParams = classInstance.InvokeMethod("Terminate", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
if (int.Parse(outParams["ReturnValue"].ToString().Trim()) != 0)
{
return false;
}
else
{
return StartProcess(ProcessName);
}
}
catch (ManagementException err)
{
Console.WriteLine("An error occurred while trying to execute the WMI method: " + err.Message);
return false;
}
}