当前位置: 首页>>代码示例>>C#>>正文


C# ManagementClass.GetMethodParameters方法代码示例

本文整理汇总了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;
        }
开发者ID:michael-manley,项目名称:nvpmmgr,代码行数:27,代码来源:InstantApplyDisc.cs

示例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;
            }
        }
开发者ID:davidduffett,项目名称:dropkick,代码行数:29,代码来源:WmiProcess.cs

示例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.");
            }
        }
开发者ID:computamike,项目名称:App-Utility-Store,代码行数:39,代码来源:FileShareHelper.cs

示例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"]);
        }
开发者ID:GorelH,项目名称:dropkick,代码行数:25,代码来源:WmiSpecs.cs

示例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");
            }
        }
开发者ID:Porterbg,项目名称:Freeflex,代码行数:25,代码来源:Core.cs

示例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);
            }
        }
开发者ID:BillTheBest,项目名称:rhevUP,代码行数:26,代码来源:systemOperations.cs

示例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);
        }
开发者ID:r3adm3,项目名称:cSharp-vs2012,代码行数:28,代码来源:CreateWebSite.asmx.cs

示例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);
        }
开发者ID:mihaibuzgau,项目名称:cf-windows-extensions,代码行数:65,代码来源:WindowsShare.cs

示例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());
 }
开发者ID:oblivious,项目名称:Oblivious,代码行数:9,代码来源:ProcessMethod.cs

示例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);
            }
        }
开发者ID:przemo098,项目名称:ccmmanager,代码行数:44,代码来源:PolicyHardResetAction.cs

示例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);
        }
开发者ID:cpm2710,项目名称:cellbank,代码行数:14,代码来源:RegistryMethod.cs

示例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);
     }
 }
开发者ID:mrsharpoblunto,项目名称:automaton,代码行数:14,代码来源:ShutDownUtils.cs

示例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);

            }
        }
开发者ID:minacle,项目名称:ReverseWheel,代码行数:15,代码来源:MainWindow.xaml.cs

示例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);
            }
        }
开发者ID:jbvigneron,项目名称:ShutDown,代码行数:18,代码来源:ShutdownHelper.cs

示例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);
        }
开发者ID:NathanLBCooper,项目名称:ProcessHelpers,代码行数:16,代码来源:WmiCommandRunner.cs


注:本文中的System.Management.ManagementClass.GetMethodParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。