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


C# ManagementClass.InvokeMethod方法代码示例

本文整理汇总了C#中System.Management.ManagementClass.InvokeMethod方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementClass.InvokeMethod方法的具体用法?C# ManagementClass.InvokeMethod怎么用?C# ManagementClass.InvokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementClass的用法示例。


在下文中一共展示了ManagementClass.InvokeMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: ExportReg

 public static void ExportReg(string RegKey, string SavePath, string ServerName)
 {
     string path = "\"" + SavePath + "\"";
     string key = "\"" + RegKey + "\"";
     object[] theProcessToRun = { "regedit.exe /e " + path + " " + key + "" };
     ManagementClass mClass = new ManagementClass(@"\\" + ServerName + @"\root\cimv2:Win32_Process");
     mClass.InvokeMethod("Create", theProcessToRun);
 }
开发者ID:rogerlio,项目名称:csharp-proj,代码行数:8,代码来源:wmi.cs

示例6: 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

示例7: 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

示例8: RemoteExec

 private void RemoteExec()
 {
     var processToRun = new[] { "notepad.exe" };
     var connection = new ConnectionOptions();
     connection.Username = "celine";
     connection.Password = "nothing";
     connection.Authentication = AuthenticationLevel.Connect;
     var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", "192.168.9.101"), connection);
     var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
     wmiProcess.InvokeMethod("Create", processToRun);
 }
开发者ID:mind0n,项目名称:hive,代码行数:11,代码来源:RemoteExecForm.cs

示例9: RemoteExecute

		public object RemoteExecute(string command)
		{
			object[] theProcessToRun = { command };
			ConnectionOptions theConnection = new ConnectionOptions();
			theConnection.Timeout = TimeSpan.FromSeconds(Timeout_Second);
			theConnection.Username = CommandExecutionContext.Instance.CurrentMachine.DomainUsername;
			theConnection.Password = CommandExecutionContext.Instance.CurrentMachine.Password;
			ManagementScope theScope = new ManagementScope("\\\\" + CommandExecutionContext.Instance.CurrentMachine.Address + "\\root\\cimv2", theConnection);
			ManagementClass theClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
			object rlt = theClass.InvokeMethod("Create", theProcessToRun);
			return rlt;
		}
开发者ID:mind0n,项目名称:hive,代码行数:12,代码来源:RemoteExecuteCommand.cs

示例10: 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

示例11: 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

示例12: InvokeRemoteCommand

        /// <summary>
        /// Invoca un comando en un servidor remotamente.
        /// </summary>
        /// <param name="ipServer"></param>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        public static string InvokeRemoteCommand(string ipServer, string user, string password, string command)
        {
            try
            {
                var processToRun = new[] { command };
                var connection = new ConnectionOptions { Username = user, Password = password };
                var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", ipServer), connection);
                var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
                var result = wmiProcess.InvokeMethod("Create", processToRun);

                return result.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:domitienda,项目名称:DomiLibrary,代码行数:25,代码来源:WmiHelper.cs

示例13: EnumerateKeys

        public static string[] EnumerateKeys(ManagementScope connectionScope,
                                             baseKey BaseKey,
                                             string key)
        {
            ManagementClass registryTask = new ManagementClass(connectionScope,
                           new ManagementPath("DEFAULT:StdRegProv"), new ObjectGetOptions());
            ManagementBaseObject methodParams = registryTask.GetMethodParameters("EnumKey");

            methodParams["hDefKey"] = BaseKey;
            methodParams["sSubKeyName"] = key;

            ManagementBaseObject exitCode = registryTask.InvokeMethod("EnumKey",
                                                        methodParams, null);
            System.String[] subKeys;
            subKeys = (string[])exitCode["sNames"];
            return subKeys;
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:17,代码来源:RegistryMethod.cs

示例14: getProfile

        /*
         *Method that execute a WMI command on a remote computer and return all the profile folders' name
         * in an arraylist
         */
        public static ArrayList getProfile(string computername)
        {
            //List to store the user profiles
            ArrayList profileList = new ArrayList();

            //Line of the file written on the client
            string line;

            ConnectionOptions connOptions = new ConnectionOptions();
            ObjectGetOptions objectGetOptions = new ObjectGetOptions();
            ManagementPath managementPath = new ManagementPath("Win32_Process");

            //To use caller credential
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", computername), connOptions);
            manScope.Connect();
            InvokeMethodOptions methodOptions = new InvokeMethodOptions(null, System.TimeSpan.MaxValue);
            ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
            ManagementBaseObject inParams = processClass.GetMethodParameters("Create");

            //The command to execute to get the profile folder and write the result to C:\\tmp.txt
            inParams["CommandLine"] = "cmd /c " + "dir C:\\Users /B" + " > c:\\tmp.txt";
            ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams,methodOptions);

            //Arbitratry delay to make sure that the command is done
            Thread.Sleep(2000);

            //Reading the result file
            StreamReader sr = new StreamReader("\\\\" + computername + "\\c$\\tmp.txt");
            line = sr.ReadLine();

            //While there are profile
            while (line != null)
            {
              //Add the profile to the arraylist
              profileList.Add(line);
              line = sr.ReadLine();

            }

            sr.Close();

            return profileList;
        }
开发者ID:banctilrobitaille,项目名称:RemoteScriptLauncher,代码行数:49,代码来源:CommUtility.cs

示例15: ShareCreate

 internal int ShareCreate(string ShareName, string FolderPath, string Description)
 {
     ManagementClass mgmtClass = new ManagementClass("Win32_Share");
     ManagementBaseObject inParams = mgmtClass.GetMethodParameters("Create");
     ManagementBaseObject outParams;
     inParams["Description"] = Description;
     inParams["Name"] = ShareName;
     inParams["Path"] = FolderPath;
     inParams["Type"] = 0x0; //disk drive
     inParams["Access"] = SecurityDescriptor();  //for Everyone full perms
     outParams = mgmtClass.InvokeMethod("Create", inParams, null);
     if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
     {
         string errCode = Enum.GetName(typeof(shareCreateErrorCodes), outParams.Properties["ReturnValue"].Value);
         MessageBox.Show(String.Format("Unable to create a network share. The error message was {0}\n\nShareName = {1}\nFolderPath = {2}", errCode, ShareName, FolderPath) );
         return 1;
     }
     else return 0;
 }
开发者ID:jwsmith41,项目名称:TAFlashShare,代码行数:19,代码来源:ShareFolder.cs


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