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


C# ManagementClass.SetPropertyValue方法代码示例

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


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

示例1: addIPPort

        private void addIPPort()
        {
            var conn = new ConnectionOptions
            {
                EnablePrivileges = true,
                Impersonation = ImpersonationLevel.Impersonate
            };

            var mPath = new ManagementPath("Win32_TCPIPPrinterPort");

            var mScope = new ManagementScope(@"\\.\root\cimv2", conn)
            {
                Options =
                {
                    EnablePrivileges = true,
                    Impersonation = ImpersonationLevel.Impersonate
                }
            };

            var mPort = new ManagementClass(mScope, mPath, null).CreateInstance();

            var remotePort = 9100;

            try
            {
                if (IP != null && IP.Contains(":"))
                {
                    var arIP = IP.Split(':');
                    if (arIP.Length == 2)
                        remotePort = int.Parse(arIP[1]);
                }
            }
            catch (Exception ex)
            {
                Log.Error(LogName, "Could not parse port from IP");
                Log.Error(LogName, ex);
            }

            mPort.SetPropertyValue("Name", Port);
            mPort.SetPropertyValue("Protocol", 1);
            mPort.SetPropertyValue("HostAddress", IP);
            mPort.SetPropertyValue("PortNumber", remotePort);
            mPort.SetPropertyValue("SNMPEnabled", false);

            var put = new PutOptions
            {
                UseAmendedQualifiers = true,
                Type = PutType.UpdateOrCreate
            };
            mPort.Put(put);
        }
开发者ID:uw-it-cte,项目名称:fog-client,代码行数:51,代码来源:LocalPrinter.cs

示例2: install

        public Boolean install(long maxWait)
        {
            long waited = 0L;
            int port = 9100;
            if (isComplete())
            {
                if (maxWait > 0)
                {
                    //if ( strFile.Length == 0 || File.Exists(strFile))
                    //{
                        if (strIP != null && strIP.Length > 0 )
                        {
                            if (strIP.Contains(":"))
                            {
                                String[] arIP = strIP.Split(new char[] { ':' });
                                if (arIP.Length == 2)
                                {
                                    strIP = arIP[0];
                                    try
                                    {
                                        port = Int32.Parse( arIP[1] );
                                    }
                                    catch
                                    {

                                    }
                                }
                            }

                            ConnectionOptions conn = new ConnectionOptions();
                            conn.EnablePrivileges = true;
                            conn.Impersonation = ImpersonationLevel.Impersonate;

                            ManagementPath mPath = new ManagementPath("Win32_TCPIPPrinterPort");

                            ManagementScope mScope = new ManagementScope(@"\\.\root\cimv2", conn);
                            mScope.Options.EnablePrivileges = true;
                            mScope.Options.Impersonation = ImpersonationLevel.Impersonate;

                            ManagementObject mPort = new ManagementClass(mScope, mPath, null).CreateInstance();

                            mPort.SetPropertyValue("Name", "IP_" + strIP);
                            mPort.SetPropertyValue("Protocol", 1);
                            mPort.SetPropertyValue("HostAddress", strIP);
                            mPort.SetPropertyValue("PortNumber", port);
                            mPort.SetPropertyValue("SNMPEnabled", false);

                            PutOptions put = new PutOptions();
                            put.UseAmendedQualifiers = true;
                            put.Type = PutType.UpdateOrCreate;
                            mPort.Put(put);
                        }

                        Process proc;
                        Boolean blIsIPP = false;

                        if (strPort.Trim().ToLower().StartsWith("ipp://"))
                        {
                            // iprint installation
                            proc = new Process();
                            proc.StartInfo.FileName = @"c:\windows\system32\iprntcmd.exe";
                            proc.StartInfo.Arguments = " -a no-gui \"" + strPort + "\"";
                            proc.StartInfo.CreateNoWindow = true;
                            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            proc.Start();
                            blIsIPP = true;
                        }
                        else if (strAlias.Trim().ToLower().StartsWith("\\\\"))
                        {
                            // Add per machine printer connection
                            proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /ga /n " + strAlias);
                            proc.WaitForExit(120000);
                            // Add printer network connection, download the drivers from the print server
                            proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /in /n " + strAlias);
                            proc.WaitForExit(120000);
                            bounceSpooler();
                        }
                        else
                        {
                            // Normal Installation
                            proc = Process.Start("rundll32.exe", getInstallArguments());
                        }

                        while (!proc.HasExited)
                        {
                            sleep(100);
                            waited += 100;
                            if (waited > maxWait)
                            {
                                proc.Kill();
                                strError = "Max install time exceeded (" + maxWait + ")";
                                return false;
                            }
                        }

                        if (blIsIPP)
                        {
                            strError = "IPP Return codes unknown";
                            return true;
                        }
//.........这里部分代码省略.........
开发者ID:need2,项目名称:fogproject,代码行数:101,代码来源:MOD_PrinterManager.cs

示例3: Add

        public override void Add()
        {
            Log.Entry(LogName, "Attempting to add printer:");
            Log.Entry(LogName, string.Format("--> Name = {0}", Name));
            Log.Entry(LogName, string.Format("--> IP = {0}", IP));
            Log.Entry(LogName, string.Format("--> Port = {0}", Port));

            if (string.IsNullOrEmpty(IP) || !Name.StartsWith("\\\\")) return;

            if (IP.Contains(":"))
            {
                var arIP = IP.Split(':');
                if (arIP.Length == 2)
                {
                    IP = arIP[0];
                    Port = arIP[1];
                }
            }

            var conn = new ConnectionOptions
            {
                EnablePrivileges = true,
                Impersonation = ImpersonationLevel.Impersonate
            };

            var mPath = new ManagementPath("Win32_TCPIPPrinterPort");

            var mScope = new ManagementScope(@"\\.\root\cimv2", conn)
            {
                Options =
                {
                    EnablePrivileges = true,
                    Impersonation = ImpersonationLevel.Impersonate
                }
            };

            var mPort = new ManagementClass(mScope, mPath, null).CreateInstance();

            if (mPort != null)
            {
                mPort.SetPropertyValue("Name", "IP_" + IP);
                mPort.SetPropertyValue("Protocol", 1);
                mPort.SetPropertyValue("HostAddress", IP);
                mPort.SetPropertyValue("PortNumber", Port);
                mPort.SetPropertyValue("SNMPEnabled", false);

                var put = new PutOptions
                {
                    UseAmendedQualifiers = true,
                    Type = PutType.UpdateOrCreate
                };
                mPort.Put(put);
            }

            if (!Name.StartsWith("\\\\")) return;

            // Add per machine printer connection
            var proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /ga /n " + Name);
            if (proc != null) proc.WaitForExit(120000);
            // Add printer network connection, download the drivers from the print server
            proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /in /n " + Name);
            if (proc != null) proc.WaitForExit(120000);
        }
开发者ID:uw-it-cte,项目名称:fog-client,代码行数:63,代码来源:NetworkPrinter.cs


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