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


C# Management.InvokeMethodOptions类代码示例

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


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

示例1: 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;
            }
        }
开发者ID:kashivreddy,项目名称:openstack-guest-agents-windows-xenserver,代码行数:25,代码来源:SetHostnameAction.cs

示例2: AsynExecute

        /// <summary>
        /// Run a command on the remote machine in asynchronous mode. After execute this request, use
        /// the method GetReturnValue to examine if the command has completed.
        /// </summary>
        /// <param name="args">The command to be executed. For example, 
        /// to run an exe, the commandLine is like “c:\test.exe –a –b”</param>
        /// <returns>The processId of the process.if the execute fails, return processId=0</returns>
        public uint AsynExecute(string args)
        {
            UInt32 processId;
            if (isCreateShareFolder == false)
            {
                Connect(null, null);
            }
            else
            {
                processId = 0;
            }

            string fileName = RandomString(20) + ".txt";
            string commandLine = "cmd /c " + args + " 2> " + remoteLogPath + "\\" + fileName + " 1>&2";

            ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
            inParams["CommandLine"] = commandLine;
            InvokeMethodOptions methodOption = new InvokeMethodOptions(null, System.TimeSpan.MaxValue);

            ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, methodOption);
            processId = (UInt32)outParams["ProcessId"];
            processIdAndFileMap.Add(processId, fileName);

            return (uint)processId;
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:32,代码来源:RemoteCommandLine.cs

示例3: DeleteItems

        public Int32 DeleteItems(uint Flags, string [] Paths)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_OfflineFilesCache");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("DeleteItems");
            InParams["Flags"] = Flags;
            InParams["Paths"] = Paths;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "DeleteItems", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:15,代码来源:Win32_OfflineFilesCache.cs

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

示例5: DefragAnalysis

        public Int32 DefragAnalysis(out object DefragAnalysis, out bool DefragRecommended)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementBaseObject InParams = null;
            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "DefragAnalysis", InParams, Options);
            DefragAnalysis = (Object)OutParams["DefragAnalysis"];
            DefragRecommended = (Boolean)OutParams["DefragRecommended"];

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:13,代码来源:Win32_Volume.cs

示例6: Defrag

        public Int32 Defrag(bool Force, out object DefragAnalysis)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_Volume");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("Defrag");
            InParams["Force"] = Force;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "Defrag", InParams, Options);
            DefragAnalysis = (Object)OutParams["DefragAnalysis"];

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:15,代码来源:Win32_Volume.cs

示例7: AddPrinterConnection

        public Int32 AddPrinterConnection(string Name)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_Printer");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("AddPrinterConnection");
            InParams["Name"] = Name;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "AddPrinterConnection", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:14,代码来源:Win32_Printer.cs

示例8: ScheduleAutoChk

        public Int32 ScheduleAutoChk(string [] LogicalDisk)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_LogicalDisk");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("ScheduleAutoChk");
            InParams["LogicalDisk"] = LogicalDisk;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "ScheduleAutoChk", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:14,代码来源:Win32_LogicalDisk.cs

示例9: Chkdsk

        public Int32 Chkdsk(bool FixErrors, bool ForceDismount, bool OkToRunAtBootUp, bool RecoverBadSectors, bool SkipFolderCycle, bool VigorousIndexCheck)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_LogicalDisk");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("Chkdsk");
            InParams["FixErrors"] = FixErrors;
            InParams["ForceDismount"] = ForceDismount;
            InParams["OkToRunAtBootUp"] = OkToRunAtBootUp;
            InParams["RecoverBadSectors"] = RecoverBadSectors;
            InParams["SkipFolderCycle"] = SkipFolderCycle;
            InParams["VigorousIndexCheck"] = VigorousIndexCheck;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "Chkdsk", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:19,代码来源:Win32_LogicalDisk.cs

示例10: Create

        public Int32 Create(object Access, string Description, uint MaximumAllowed, string Name, string Password, string Path, uint Type)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_Share");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("Create");
            InParams["Access"] = Access;
            InParams["Description"] = Description;
            InParams["MaximumAllowed"] = MaximumAllowed;
            InParams["Name"] = Name;
            InParams["Password"] = Password;
            InParams["Path"] = Path;
            InParams["Type"] = Type;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "Create", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:20,代码来源:Win32_Share.cs

示例11: Format

        public Int32 Format(uint ClusterSize, bool EnableCompression, string FileSystem, string Label, bool QuickFormat, uint Version)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_Volume");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("Format");
            InParams["ClusterSize"] = ClusterSize;
            InParams["EnableCompression"] = EnableCompression;
            InParams["FileSystem"] = FileSystem;
            InParams["Label"] = Label;
            InParams["QuickFormat"] = QuickFormat;
            InParams["Version"] = Version;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "Format", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:19,代码来源:Win32_Volume.cs

示例12: GetEffectivePermission

        public Int32 GetEffectivePermission(uint Permissions)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_CodecFile");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("GetEffectivePermission");
            InParams["Permissions"] = Permissions;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "GetEffectivePermission", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:14,代码来源:Win32_CodecFile.cs

示例13: ChangeSecurityPermissionsEx

        public Int32 ChangeSecurityPermissionsEx(uint Option, bool Recursive, object SecurityDescriptor, string StartFileName, out string StopFileName)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_CodecFile");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("ChangeSecurityPermissionsEx");
            InParams["Option"] = Option;
            InParams["Recursive"] = Recursive;
            InParams["SecurityDescriptor"] = SecurityDescriptor;
            InParams["StartFileName"] = StartFileName;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "ChangeSecurityPermissionsEx", InParams, Options);
            StopFileName = (String)OutParams["StopFileName"];

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:18,代码来源:Win32_CodecFile.cs

示例14: ChangeSecurityPermissions

        public Int32 ChangeSecurityPermissions(uint Option, object SecurityDescriptor)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_CodecFile");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("ChangeSecurityPermissions");
            InParams["Option"] = Option;
            InParams["SecurityDescriptor"] = SecurityDescriptor;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "ChangeSecurityPermissions", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:15,代码来源:Win32_CodecFile.cs

示例15: IsCompatible

        public Int32 IsCompatible(string ElementToCheck)
        {
            System.Management.InvokeMethodOptions Options = new System.Management.InvokeMethodOptions();
            Options.Timeout = new TimeSpan(0, 0, 10);
            ManagementClass WMIClass = new ManagementClass("Win32_BaseBoard");
            ManagementBaseObject InParams = WMIClass.GetMethodParameters("IsCompatible");
            InParams["ElementToCheck"] = ElementToCheck;

            ManagementBaseObject OutParams = null;
            OutParams = InvokeMethod(m_MyPath, "IsCompatible", InParams, Options);

            Int32 numericResult = Convert.ToInt32(OutParams["ReturnValue"]);
            return numericResult;
        }
开发者ID:jasrajbishnoi,项目名称:wiitransfer,代码行数:14,代码来源:Win32_BaseBoard.cs


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