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


C# Management.ManagementPath类代码示例

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


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

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

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

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

示例4: addComputerToCollection

        protected void addComputerToCollection(string resourceID, string collectionID)
        {
            /*  Set collection = SWbemServices.Get ("SMS_Collection.CollectionID=""" & CollID &"""")

                  Set CollectionRule = SWbemServices.Get("SMS_CollectionRuleDirect").SpawnInstance_()
                  CollectionRule.ResourceClassName = "SMS_R_System"
                  CollectionRule.RuleName = "Static-"&ResourceID
                  CollectionRule.ResourceID = ResourceID
                  collection.AddMembershipRule CollectionRule*/

            //o.Properties["ResourceID"].Value.ToString();

            var pathString = "\\\\srv-cm12-p01.srv.aau.dk\\ROOT\\SMS\\site_AA1" + ":SMS_Collection.CollectionID=\"" + collectionID + "\"";
            ManagementPath path = new ManagementPath(pathString);
            ManagementObject obj = new ManagementObject(path);

            ManagementClass ruleClass = new ManagementClass("\\\\srv-cm12-p01.srv.aau.dk\\ROOT\\SMS\\site_AA1" + ":SMS_CollectionRuleDirect");

            ManagementObject rule = ruleClass.CreateInstance();

            rule["RuleName"] = "Static-"+ resourceID;
            rule["ResourceClassName"] = "SMS_R_System";
            rule["ResourceID"] = resourceID;

            obj.InvokeMethod("AddMembershipRule", new object[] { rule });
        }
开发者ID:yrke,项目名称:AAUWebMgmt,代码行数:26,代码来源:ComputerInfo.aspx.cs

示例5: WmiEventSink

		protected WmiEventSink(ManagementOperationObserver watcher, object context, ManagementScope scope, string path, string className)
		{
			try
			{
				this.context = context;
				this.watcher = watcher;
				this.className = className;
				this.isLocal = false;
				if (path != null)
				{
					this.path = new ManagementPath(path);
					if (string.Compare(this.path.Server, ".", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(this.path.Server, Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
					{
						this.isLocal = true;
					}
				}
				if (scope != null)
				{
					this.scope = scope.Clone();
					if (path == null && (string.Compare(this.scope.Path.Server, ".", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(this.scope.Path.Server, Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0))
					{
						this.isLocal = true;
					}
				}
				WmiNetUtilsHelper.GetDemultiplexedStub_f(this, this.isLocal, out this.stub);
				this.hash = Interlocked.Increment(ref WmiEventSink.s_hash);
			}
			catch
			{
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:WmiEventSink.cs

示例6: CheckDeviceMacadress

        public bool CheckDeviceMacadress(string strMacadress)
        {
           
            MacAdress = strMacadress;
           
            ManagementPath cmPath = new ManagementPath("root\\sms\\site_PS1:SMS_R_SYSTEM"); 
            ManagementClass cmClass = new ManagementClass(cmPath);
            ManagementObjectCollection cmCollection = cmClass.GetInstances();

            DeviceFound = false;

            foreach (ManagementObject deviceInfo in cmCollection)
            {
                string[] listCmDeviceMacAdresses = (string[])deviceInfo["MACAddresses"];
                foreach (string MacAdressExist in listCmDeviceMacAdresses)
                {
                    if (MacAdressExist == MacAdress)
                    {
                        DeviceFound = true;
                    }
                    
                }
         
            }

            return DeviceFound;
        }
开发者ID:aramiz84,项目名称:sllCreateComputer,代码行数:27,代码来源:CheckMacAdress.cs

示例7: WmiWrapper

 public WmiWrapper(ManagementPath path)
 {
     _scope = new ManagementScope(path)
     {
         Options = { Impersonation = ImpersonationLevel.Impersonate }
     };
 }
开发者ID:b1thunt3r,项目名称:WinInfo,代码行数:7,代码来源:WMIWrapper.cs

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

示例9: LoadDeviceList

        private void LoadDeviceList()
        {
            devices.Clear();
            devices.Add(new SoundDevice("Default", "0000", "0000"));

            ManagementPath path = new ManagementPath();
            ManagementClass devs = null;
            path.Server = ".";
            path.NamespacePath = @"root\CIMV2";
            path.RelativePath = @"Win32_SoundDevice";
            using (devs = new ManagementClass(new ManagementScope(path), path, new ObjectGetOptions(null, new TimeSpan(0, 0, 0, 2), true)))
            {
                ManagementObjectCollection moc = devs.GetInstances();

                foreach (ManagementObject mo in moc)
                {
                    PropertyDataCollection devsProperties = mo.Properties;
                    string devid = devsProperties["DeviceID"].Value.ToString();
                    if (devid.Contains("PID_"))
                    {
                        string vid = devid.Substring(devid.IndexOf("VID_") + 4, 4);
                        string pid = devid.Substring(devid.IndexOf("PID_") + 4, 4);

                        devices.Add(new SoundDevice(devsProperties["Caption"].Value.ToString(), vid, pid));

                    }
                }
            }
        }
开发者ID:suleymansahin07,项目名称:NoCableLauncher,代码行数:29,代码来源:Settings.cs

示例10: ConnectToClient

 private ManagementScope ConnectToClient(string hostname)
 {
     ManagementPath oPath = new ManagementPath(string.Format("\\\\{0}\\ROOT\\CCM", hostname));
     ConnectionOptions oCon = new ConnectionOptions();
     oCon.Impersonation = ImpersonationLevel.Impersonate;
     oCon.EnablePrivileges = true;
     ManagementScope oMs = new ManagementScope(oPath, oCon);
     try
     {
         oMs.Connect();
     }
     catch (System.UnauthorizedAccessException ex)
     {
         return null;
     }
     catch (Exception e)
     {
         return null;
     }
     finally
     {
         GC.Collect();
     }
     return oMs;
 }
开发者ID:przemo098,项目名称:ccmmanager,代码行数:25,代码来源:PolicyDownloadAction.cs

示例11: ChangeServiceStartMode

        /// <summary>
        /// </summary>
        /// <param name="objz"></param>
        /// <param name="cmdTag"></param>
        /// <returns></returns>
        public static bool ChangeServiceStartMode(WmiServiceObj objz, string cmdTag)
        {
            bool bRel;
            var sc = new ServiceController(objz.Name);
            string startupType = "";

            var myPath = new ManagementPath
            {
                Server = Environment.MachineName,
                NamespacePath = @"root\CIMV2",
                RelativePath = string.Format("Win32_Service.Name='{0}'", sc.ServiceName)
            };
            switch (cmdTag)
            {
                case "41":
                    startupType = "Manual";
                    break;
                case "42":
                    startupType = "Auto";
                    break;
                case "43":
                    startupType = "Disabled";
                    break;
            }
            using (var service = new ManagementObject(myPath))
            {
                ManagementBaseObject inputArgs = service.GetMethodParameters("ChangeStartMode");
                inputArgs["startmode"] = startupType;
                service.InvokeMethod("ChangeStartMode", inputArgs, null);
                bRel = true;
            }

            sc.Refresh();
            return bRel;
        }
开发者ID:GininDev,项目名称:ServicesInforCollector,代码行数:40,代码来源:ShellHelper.cs

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

示例13: RemoteComputerInfo

        private List<String> RemoteComputerInfo(string Username, string Password, string IP, string sWin32class)
        {
            List<String> resultList = new List<String>();

            ConnectionOptions options = new ConnectionOptions();
            options.Username = Username;
            options.Password = Password;
            options.Impersonation = ImpersonationLevel.Impersonate;
            options.EnablePrivileges = true;
            try
            {
                ManagementScope mgtScope = new ManagementScope(string.Format("\\\\{0}\\root\\cimv2", IP), options);
                mgtScope.Connect();

                ObjectGetOptions objectGetOptions = new ObjectGetOptions();
                ManagementPath mgtPath = new ManagementPath(sWin32class);
                ManagementClass mgtClass = new ManagementClass(mgtScope, mgtPath, objectGetOptions);

                PropertyDataCollection prptyDataCollection = mgtClass.Properties;

                foreach (ManagementObject mgtObject in mgtClass.GetInstances())
                {
                    foreach (PropertyData property in prptyDataCollection)
                    {
                        try
                        {
                            string mobjvalue = "";
                            if (mgtObject.Properties[property.Name].Value == null)
                            {
                                mobjvalue = "null";
                            }
                            else
                            {
                                mobjvalue = mgtObject.Properties[property.Name].Value.ToString();
                            }

                            if (ShouldInclude(property.Name))
                            {
                                resultList.Add(string.Format(property.Name + ":  " + mobjvalue));
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                resultList.Add(string.Format("Can't Connect to Server: {0}\n{1}", IP, ex.Message));
            }

            return resultList;
        }
开发者ID:PaulWillis,项目名称:ServerInfoWMI,代码行数:55,代码来源:SystemInformation.cs

示例14: WMIProvider

        //private Provider oProv;

        public WMIProvider(string hostname)
        {
            oRootPath = new ManagementPath(string.Format("\\\\{0}\\ROOT\\CIMV2", hostname));
            //oCCMPath = new ManagementPath(string.Format("\\\\{0}\\ROOT\\CCM", hostname));
            oCon.Impersonation = ImpersonationLevel.Impersonate;
            oCon.EnablePrivileges = true;
            oRootMs = new ManagementScope(oRootPath, oCon);
            this.Hostname = hostname;
            //oProv = new Provider(oRootPath.NamespacePath);
            
        }
开发者ID:przemo098,项目名称:ccmmanager,代码行数:13,代码来源:WMIProvider.cs

示例15: ManagementScope

 internal ManagementScope(ManagementPath path, IWbemServices wbemServices, ConnectionOptions options)
 {
     if (path != null)
     {
         this.Path = path;
     }
     if (options != null)
     {
         this.Options = options;
     }
     this.wbemServices = wbemServices;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:ManagementScope.cs


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