Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //IWMIHelper helper = new WMIHelper("root\\CimV2");

            //Process p = new Process();
            //p.Create("C:/Windows/notepad.exe", null, null);

            //List<NetworkAdapterConfiguration> interfaces = helper.Query<NetworkAdapterConfiguration>().ToList();

            //Printer printer = helper.QueryFirstOrDefault<Printer>();

            //List<Printer> printers = helper.Query<Printer>().ToList();

            //foreach (Printer p in printers)
            //{
            //    p.RenamePrinter("Newly renamed printer");
            //}

            //Output outp = new Output
            //{
            //    PanelID = 10,
            //    ReaderID = 1,
            //    Hostname = "ONGUARD01",
            //    Name = "ONGUARD01"
            //};

            //outp.Activate();

            //List<Process> processes = helper.Query<Process>().ToList();

            //foreach (Process p in processes)
            //{
            //    //dynamic d = p.GetOwnerSid();
            //    ProcessOwner po = p.GetOwner();
            //    //int res = p.AttachDebugger();
            //}

            //var dynDevices = helper.Query("SELECT * FROM Win32_PnPEntity");

            //var processors = helper.Query<Processor>();

            //List<Processor> procesors = helper.Query<Processor>().ToList();

            //List<Device> devices = helper.Query<Device>().ToList()
            //    .Where(p => (p.Name ?? "")
            //    .Contains("Intel")).ToList();

            //foreach (Device d in devices)
            //{
            //    Console.WriteLine(d.Name);
            //}

            //Person person = new Person
            //{
            //    FirstName = "John",
            //    DocumentNumber = "9995",
            //};

            //helper.AddInstance(person);

            //Person queryPersonSingle = helper.Query<Person>("SELECT * FROM Lnl_Cardholder WHERE LASTNAME = 'Doe Modified'").SingleOrDefault();

            //queryPersonSingle.Lastname = "Doe Modified";

            //helper.UpdateInstance(queryPersonSingle);

            //List<Person> queryPerson = helper.Query<Person>("SELECT * FROM Lnl_Cardholder WHERE LASTNAME = 'Lopez'").ToList();

            //WMIWatcher watcher = new WMIWatcher("root\\CimV2", "SELECT * FROM Win32_ProcessStartTrace", typeof(Process));
            WMIWatcher watcher = new WMIWatcher("root\\CimV2", "SELECT * FROM Win32_ProcessStartTrace");

            watcher.WMIEventArrived += Watcher_WMIEventArrived;

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //var CimV2searcher = new WMISearcher();
            var CimV2searcher = new WMISearcher(scope: "root\\CimV2", hostname: "W2019SRV-DEV",
                                                username: "******", password: "******");; //root\CimV2 is the defualt namespace



            #region read data under root\CimV2

            var networks = CimV2searcher.Query <NetworkAdapter>();
            foreach (var network in networks)
            {
                Console.WriteLine("NetworkAdapter Data :");
                Console.WriteLine(network);
            }

            var networkLoginProfiles = CimV2searcher.Query <NetworkLoginProfile>();
            foreach (var networkLoginProfile in networkLoginProfiles)
            {
                Console.WriteLine("NetworkLoginProfile Data :");
                Console.WriteLine(networkLoginProfile);
            }
            #endregion


            #region execute methods under root\CimV2

            var printer = CimV2searcher.Query <Printer>().Where(x => x.Name == "Brother RJ-4030").FirstOrDefault();
            if (printer != null)
            {
                printer.RenamePrinter(newName: "Brother RJ-4030xXx");
            }
            #endregion

            var wmiSearcher = new WMISearcher(@"Root\wmi");


            #region  read data under Root\wmi


            var monitorBrightness = wmiSearcher.Query <WmiMonitorBrightness>();
            foreach (var monitor in monitorBrightness)
            {
                Console.WriteLine(monitor);
            }
            #endregion

            #region execute methods under Root\wmi

            var monitorBrightnessMethods = wmiSearcher.Query <WmiMonitorBrightnessMethods>();
            foreach (var method in monitorBrightnessMethods)
            {
                Console.WriteLine(method);
                method.WmiSetBrightness(Timeout: UInt32.MaxValue, Brightness: 100);
            }

            #endregion

            #region watch events
            //can throw Class is not an event class or accsess denied if not have right previlage
            var watcher = new WMIWatcher(@"\root\CIMV2", typeof(ProcessStartTrace));
            watcher.WMIEventArrived += watcher_WMIEventArrived;

            #endregion

            Console.ReadKey();
        }