Example #1
0
        static void Main(string[] args)
        {
            var sb          = new StringBuilder();
            var scope       = Wmi.GetScope();
            var enumOptions = new EnumerationOptions {
                EnsureLocatable = true
            };

            var processor = Processor.GetInstances(scope, enumOptions).Cast <Processor>().FirstOrDefault();

            if (processor != null)
            {
                sb.AppendLine(string.Format("{0,-22} {1}", "Name:", processor.Name));
                sb.AppendLine(string.Format("{0,-22} {1} ({2}-bit)", "Architecture:",
                                            processor.Architecture.GetDescription(), processor.DataWidth));
                sb.AppendLine(string.Format("{0,-22} {1}", "Processor ID:", processor.ProcessorId));
            }
            sb.AppendLine();

            var os = new OperatingSystem0(scope);

            {
                sb.AppendLine(string.Format("{0,-22} {1} [{2}] ({3})", "Operating System:", os.Caption, os.Version, os.OSArchitecture));
                sb.AppendLine(string.Format("{0,-22} {1:yyyy-MM-dd HH:mm:ss} ({2,3:dd} days {2:hh}:{2:mm}:{2:ss})",
                                            "Install Date", os.InstallDate, (DateTime.Now - os.InstallDate)));
                sb.AppendLine(string.Format("{0,-22} {1:yyyy-MM-dd HH:mm:ss} ({2,3:dd} days {2:hh}:{2:mm}:{2:ss})",
                                            "Last boot", os.LastBootUpTime, (DateTime.Now - os.LastBootUpTime)));
            }

            sb.AppendLine();

            Console.WriteLine(sb.ToString());
            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }
Example #2
0
        public Tui()
        {
            var scope       = Wmi.GetScope();
            var enumOptions = new EnumerationOptions {
                EnsureLocatable = true
            };

            _system          = ComputerSystem.GetInstances(scope, enumOptions).Cast <ComputerSystem>().FirstOrDefault();
            _processor       = Processor.GetInstances(scope, enumOptions).Cast <Processor>().FirstOrDefault();
            _networkAdapters = NetworkAdapter.GetInstances(scope, enumOptions)
                               .Cast <NetworkAdapter>()
                               .Where(n => n.PhysicalAdapter);
            _operatingSystem = new OperatingSystem0(scope);
        }
Example #3
0
		public void ExecuteRemoteProcess(string command)
		{
			Wmi cimv2 = new Wmi(ServerNameSettings, "root\\cimv2");
			ManagementClass objProcess = cimv2.GetWmiClass("Win32_Process");

			// run process
			object[] methodArgs = { command, null, null, 0 };
			objProcess.InvokeMethod("Create", methodArgs);

			// process ID
			int processId = Convert.ToInt32(methodArgs[3]);

			// wait until finished
			// Create event query to be notified within 1 second of 
			// a change in a service
			WqlEventQuery query =
				new WqlEventQuery("__InstanceDeletionEvent",
				new TimeSpan(0, 0, 1),
				"TargetInstance isa \"Win32_Process\"");

			// Initialize an event watcher and subscribe to events 
			// that match this query
			ManagementEventWatcher watcher = new ManagementEventWatcher(cimv2.GetScope(), query);
			// times out watcher.WaitForNextEvent in 20 seconds
			watcher.Options.Timeout = new TimeSpan(0, 0, 20);

			// Block until the next event occurs 
			// Note: this can be done in a loop if waiting for 
			//        more than one occurrence
			while (true)
			{
				ManagementBaseObject e = null;

				try
				{
					// wait untill next process finish
					e = watcher.WaitForNextEvent();
				}
				catch
				{
					// nothing has been finished in timeout period
					return; // exit
				}

				// check process id
				int pid = Convert.ToInt32(((ManagementBaseObject)e["TargetInstance"])["ProcessID"]);
				if (pid == processId)
				{
					//Cancel the subscription
					watcher.Stop();

					// exit
					return;
				}
			}
		}