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


C# Management.ConnectionOptions类代码示例

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


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

示例1: ShowUserSID

 public static string ShowUserSID(string username)
 {
     // local scope
     string[] unames = username.Split("\\".ToCharArray(),2);
     string d = "";
     string n = "";
     d = unames[0];
     if (unames.Length < 2)
     {
         n = unames[0];
         d = "US_IBS";
     }
     else
         n = unames[1];
     ConnectionOptions co = new ConnectionOptions();
     //co.Username = username;
     ManagementScope msc = new ManagementScope ("\\root\\cimv2",co);
     string queryString = "SELECT * FROM Win32_UserAccount where LocalAccount = false AND SIDType = 1 AND Domain = '" + d+ "' AND Name = '" + n + "'";
     //System.Windows.Forms.MessageBox.Show(queryString);
     SelectQuery q = new SelectQuery (queryString);
     query = new ManagementObjectSearcher(msc, q);
     queryCollection = query.Get();
     string res=String.Empty;
     foreach( ManagementObject mo in queryCollection )
     {
         // there should be only one here!
         res+= mo["SID"].ToString();
         //res+= mo["Name"]+"\n";
     }
     return res;
 }
开发者ID:reticon,项目名称:CCMClient,代码行数:31,代码来源:SID.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: Main

        static void Main(string[] args)
        {
            ConnectionOptions conn = new ConnectionOptions();
            conn.Username = "kingsley";//登入远端电脑的账户
            conn.Password = "111111";//登入远端电脑的密码
            ManagementPath path = new ManagementPath();

            //其中root\cimv2是固定写法
            path.Path = @"\\10.0.1.36\root\cimv2";
            ManagementScope ms = new ManagementScope();
            ms.Options = conn;
            ms.Path = path;
            ms.Connect();
            //这里的例子读取文件的最后修改日期
            ObjectQuery query = new ObjectQuery("SELECT * FROM CIM_DataFile WHERE Name = 'C:\\\\KVOffice.txt'");
            ManagementObjectSearcher  searcher = new ManagementObjectSearcher(ms,query);
            ManagementObjectCollection collection = searcher.Get();
            string time = "";
            foreach (ManagementObject obj in collection)
            {
                time = obj.Properties["LastModified"].Value.ToString().Substring(0,14);
            }
            Console.WriteLine("测试dev");
            Console.WriteLine(time);
            Console.ReadLine();
        }
开发者ID:jiangnanyishui,项目名称:Tyee_project,代码行数:26,代码来源:Program.cs

示例4: GetOperatingSystemInfo

 protected virtual void GetOperatingSystemInfo(string Name, string UserName, string Password)
 {
     if (string.IsNullOrEmpty(Name))
         throw new ArgumentNullException("Name");
     ManagementScope Scope = null;
     if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
     {
         ConnectionOptions Options = new ConnectionOptions();
         Options.Username = UserName;
         Options.Password = Password;
         Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2", Options);
     }
     else
     {
         Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2");
     }
     Scope.Connect();
     ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
     using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query))
     {
         using (ManagementObjectCollection Collection = Searcher.Get())
         {
             foreach (ManagementObject TempNetworkAdapter in Collection)
             {
                 if (TempNetworkAdapter.Properties["LastBootUpTime"].Value != null)
                 {
                     LastBootUpTime = ManagementDateTimeConverter.ToDateTime(TempNetworkAdapter.Properties["LastBootUpTime"].Value.ToString());
                 }
             }
         }
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:32,代码来源:OperatingSystem.cs

示例5: getComputerInfos

        public static String[] getComputerInfos(string computername)
        {
            String[] computerInfos = new String[2];

            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();
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(manScope, query);
            ManagementObjectCollection queryCollection = searcher.Get();

            foreach (ManagementObject m in queryCollection){

                computerInfos[0] = Convert.ToString(m["Caption"]);
                computerInfos[1] = Convert.ToString(m["Status"]);

            }

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

示例6: GetVersion

 /// <summary>
 /// Gets the version of the OS for the given machine.
 /// </summary>
 /// <param name="machineName">The machine name.</param>
 /// <param name="userName">The username.</param>
 /// <param name="password">The password.</param>
 /// <returns>The OS version.</returns>
 public static Version GetVersion(string machineName, string userName, string password)
 {
     ConnectionOptions connectionOptions = new ConnectionOptions();
     connectionOptions.Username = userName;
     connectionOptions.Password = password;
     return GetVersion(machineName, connectionOptions);
 }
开发者ID:StealFocus,项目名称:Core,代码行数:14,代码来源:OperatingSystem.cs

示例7: GetConnectOptions

        private static ConnectionOptions GetConnectOptions(string machineName)
        {
            var co = new ConnectionOptions();
            if (machineName == Environment.MachineName)
                return co;

            switch (machineName)
            {
                case "localhost":
                case "127.0.0.1":
                case "::1":
                    return co;
                default:
                    co = new ConnectionOptions
                    {
                        Authentication = AuthenticationLevel.Packet,
                        Timeout = new TimeSpan(0, 0, 30),
                        EnablePrivileges = true
                    };
                    break;
            }
            var wps = Current.Settings.Polling.Windows;
            if (wps != null && wps.AuthUser.HasValue() && wps.AuthPassword.HasValue())
            {
                co.Username = wps.AuthUser;
                co.Password = wps.AuthPassword;
            }
            return co;
        }
开发者ID:dotnetgeek,项目名称:Opserver,代码行数:29,代码来源:Wmi.cs

示例8: CallWmiShutdown

        private static void CallWmiShutdown(int flags)
        {
            // 実行前にガベージコレクトを行っておく
            GC.Collect();
            System.Threading.Thread.CurrentThread.Join(0);
            GC.WaitForPendingFinalizers();
            GC.Collect();

            //ユーザー特権を有効にするための設定を作成
            ConnectionOptions co = new ConnectionOptions();
            co.Impersonation = ImpersonationLevel.Impersonate;
            co.EnablePrivileges = true;
            //ManagementScopeを作成
            ManagementScope sc = new ManagementScope("\\ROOT\\CIMV2", co);

            //接続
            sc.Connect();
            ObjectQuery oq = new ObjectQuery("select * from Win32_OperatingSystem");
            using (ManagementObjectSearcher mos = new ManagementObjectSearcher(sc, oq)) {
                //Shutdownメソッドを呼び出す
                foreach (ManagementObject mo in mos.Get()) {
                    //パラメータを指定
                    ManagementBaseObject inParams = mo.GetMethodParameters("Win32Shutdown");
                    inParams["Flags"] = flags;
                    inParams["Reserved"] = 0;
                    //Win32Shutdownメソッドを呼び出す
                    ManagementBaseObject outParams = mo.InvokeMethod("Win32Shutdown", inParams, null);
                }
            }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:30,代码来源:Shutdown.cs

示例9: Execute

        /// <summary>
        /// Executes the specified function
        /// </summary>
        /// <param name="function">Function to execute</param>
        private void Execute(string function)
        {
            var options = new ConnectionOptions
            {
                Username = User,
                Password = Password,
                Authentication = AuthenticationLevel.PacketPrivacy
            };
            var mgmtPath = new ManagementPath
            {
                Server = Server,
                NamespacePath = "root/MicrosoftIISv2"
            };
            var mgmtScope = new ManagementScope(mgmtPath, options);
            mgmtScope.Connect();

            var siteId = GetSiteIdFromWebSiteName();
            if (!string.IsNullOrEmpty(siteId))
            {
                var selectQuery = new SelectQuery("SELECT * FROM IIsWebServer WHERE Name = 'W3SVC/" + siteId + "'");
                using (var managementObjectSearcher = new ManagementObjectSearcher(mgmtScope, selectQuery))
                {
                    foreach (ManagementObject objMgmt in managementObjectSearcher.Get())
                    {
                        objMgmt.InvokeMethod(function, new object[0]);
                    }
                }
            }
        }
开发者ID:rajanikanthr,项目名称:Algorithms-CSharp,代码行数:33,代码来源:WebsiteController.cs

示例10: Start

        public void Start(PagesPrinted callback)
        {
            Printed += callback;

            try
            {

                ManagementScope scope;

                if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
                {
                    var conn = new ConnectionOptions();
                    conn.Username = "";
                    conn.Password = "";
                    conn.Authority = "ntlmdomain:DOMAIN";
                    scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), conn);
                }
                else
                {
                    scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);
                }
                scope.Connect();

                _watcher = new ManagementEventWatcher(scope, new EventQuery(WmiQuery));
                _watcher.EventArrived += new EventArrivedEventHandler(this.WmiEventHandler);
                _watcher.Start();

            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0} Trace {1}", e.Message, e.StackTrace);
            }
        }
开发者ID:wortexx,项目名称:Footprint,代码行数:33,代码来源:PrintingMonitor.cs

示例11: checkAntiVirus

        public static List<Object[]> checkAntiVirus()
        {
            List<Object[]> av = new List<Object[]>();
            ConnectionOptions _connectionOptions = new ConnectionOptions();

            _connectionOptions.EnablePrivileges = true;
            _connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
            ManagementScope _managementScope = new ManagementScope(string.Format("\\\\{0}\\root\\SecurityCenter2", "localhost"), _connectionOptions);
            _managementScope.Connect();

            ObjectQuery _objectQuery = new ObjectQuery("SELECT * FROM AntivirusProduct");
            ManagementObjectSearcher _managementObjectSearcher = new ManagementObjectSearcher(_managementScope, _objectQuery);
            ManagementObjectCollection _managementObjectCollection = _managementObjectSearcher.Get();

            if (_managementObjectCollection.Count > 0)
            {
                Boolean updated = false;
                foreach (ManagementObject item in _managementObjectCollection)
                {
                    updated = (item["productState"].ToString() == "266240" || item["productState"].ToString() == "262144");
                    av.Add(new Object[] { item["displayName"].ToString(), updated });
                }
            }

            return av;
        }
开发者ID:jra89,项目名称:ass,代码行数:26,代码来源:WindowsSecurityChecks.cs

示例12: GetMachineName

        public string GetMachineName()
        {
            string sBoxName = null;
            this.sQuery = "select CSName from Win32_OperatingSystem";

            ConnectionOptions oXn = new ConnectionOptions();
            ManagementScope oScope = new ManagementScope("\\\\localhost", oXn);
            ObjectQuery oQuery = new ObjectQuery(this.sQuery);
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oScope, oQuery);
            ManagementObjectCollection oResults = oSearcher.Get();

            foreach (ManagementObject oResult in oResults)
            {
                try
                {
                    sBoxName = oResult["CSName"].ToString();
                    Logger.WriteEvent("Computer name: " + sBoxName, ZifliService._DEBUG);
                }
                catch
                {
                    Logger.WriteEvent("Computer name is indeterminable.", ZifliService._WARN);
                }

            }
            return sBoxName;
        }
开发者ID:BGCX261,项目名称:zifli-svn-to-git,代码行数:26,代码来源:Misc.cs

示例13: ConnectWMIScope

        public static bool ConnectWMIScope(string RemoteServer, string UserName, String Password)
        {
            bool retval = true;
            try
            {
                ConnectionOptions options = new ConnectionOptions();
                options.EnablePrivileges = true;
                options.Impersonation = ImpersonationLevel.Impersonate;
                options.Authentication = AuthenticationLevel.Packet;
                options.Username = UserName;
                options.Password = Password;
                options.Timeout = TimeSpan.FromSeconds(2);

                string ConnectionString = string.Format("\\\\{0}\\root\\cimv2", RemoteServer);
                ManagementScope scope = new ManagementScope(ConnectionString, options);
                scope.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                retval = false;
                return retval;
            }

            return retval;
        }
开发者ID:shlomipm,项目名称:SysMat_WPF,代码行数:26,代码来源:RemoteScope.cs

示例14: DriveService

		public DriveService()
		{
			// Bind to local machine
			var options = new ConnectionOptions { EnablePrivileges = true };
			var scope = new ManagementScope(@"root\CIMV2", options);

			try
			{
				var query = new WqlEventQuery
				{
					EventClassName = "__InstanceModificationEvent",
					WithinInterval = TimeSpan.FromSeconds(1),
					Condition = @"TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5" // DriveType - 5: CDROM
				};

				this.watcher = new ManagementEventWatcher(scope, query);

				// register async. event handler
				this.watcher.EventArrived += this.HandleDiscEvent;
				this.watcher.Start();
			}
			catch (Exception e)
			{
				System.Diagnostics.Debug.WriteLine(e.Message);
			}
		}
开发者ID:Runcy,项目名称:VidCoder,代码行数:26,代码来源:DriveService.cs

示例15: Main

        static void Main(string[] args)
        {
            try
            {
            string ComputerName = "localhost";
            ManagementScope Scope;

            if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
            {
                ConnectionOptions Conn = new ConnectionOptions();
                Conn.Username  = "";
                Conn.Password  = "";
                Conn.Authority = "ntlmdomain:DOMAIN";
                Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), Conn);
            }
            else
                Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);

            Scope.Connect();
            ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_DiskDrive");
            ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);

            foreach (ManagementObject WmiObject in Searcher.Get())
            {
                Console.WriteLine("{0,-35} {1,-40}","Name",WmiObject["Name"]);// String

            }
            }
            catch (Exception e)
            {
            Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace));
            }
            Console.WriteLine("Press Enter to exit");
            Console.Read();
        }
开发者ID:bgarrels,项目名称:wmi-delphi-code-creator,代码行数:35,代码来源:Template_Csharp.cs


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