internal ServiceMethods(WmiFacade facade) { if (null == facade) { throw new WmiException("Wmi Facade not initialised."); } m_facade = facade; }
internal RegistryMethods(WmiFacade facade) { if (null == facade) { throw new WmiException("Wmi Facade not initialised."); } m_wmi = facade; HKeyClassesRoot = new RegHiveProxy(facade, RegistryHive.ClassesRoot); HKeyCurrentConfig = new RegHiveProxy(facade, RegistryHive.CurrentConfig); HKeyCurrentUser = new RegHiveProxy(facade, RegistryHive.CurrentUser); HKeyLocalMachine = new RegHiveProxy(facade, RegistryHive.LocalMachine); HKeyUsers = new RegHiveProxy(facade, RegistryHive.Users); }
public void TestServiceOpCallback() { //Provider p = new Provider(); ServiceOpHandler h = new ServiceOpHandler(); ServiceMethods.ServiceMethodObserver o = new ServiceMethods.ServiceMethodObserver(); o.ObjectPut += h.HandleWmiObjectPutOp; o.ObjectReady += h.HandleWmiObjectReadyOp; o.Progress += h.HandleWmiProgressOp; o.Completed += h.HandleWmiCompletedOp; WmiFacade wmi = new WmiFacade(); Console.WriteLine(DateTime.UtcNow.ToString("o") + " : Attempting op on TestWinSvc "); //wmi.Service.Start("TestWinSvc", o); //wmi.Service.Stop("TestWinSvc", o); while (true) { Thread.Sleep(100); } }
internal RegHiveProxy(WmiFacade facade, RegistryHive hiveKey) { if (null == facade) { throw new WmiException("Wmi Facade not initialised."); } m_facade = facade; m_hiveKey = hiveKey; try { m_registry = new ManagementClass(m_facade.Scope, m_stdRegProvider, null); } catch (ManagementException x) { throw new WmiException("Encountered " + x.GetType() + " while initializing Registry Provider.\nCode: " + x.ErrorCode + "\nInfo: " + x.ErrorInformation, x); } catch (Exception x) { throw new WmiException("Encountered " + x.GetType() + " while initializing Registry Provider."); } }
public static void TestServiceController() { WmiFacade wmi = GetLocalConnection(); //WmiFacade wmi = GetRemoteConnection(); List <Service> sl = wmi.Service.GetList(); Console.WriteLine(sl); ServiceController c = new ServiceController("TestWinSvc", "localhost"); Console.WriteLine(DateTime.UtcNow.ToString("o") + " : Running ..."); try { TimeSpan t = new TimeSpan(0, 0, 0, 10); switch (c.Status) { case ServiceControllerStatus.Stopped: c.Start(); c.WaitForStatus(ServiceControllerStatus.Running, t); break; case ServiceControllerStatus.Running: c.Stop(); c.WaitForStatus(ServiceControllerStatus.Stopped, t); break; } } catch (Exception x) { Console.WriteLine(DateTime.UtcNow.ToString("o") + " : Encountered " + x.GetType() + " : " + x.Message); } Console.WriteLine(DateTime.UtcNow.ToString("o") + " : Done."); Console.WriteLine("."); }
public static void TestWmiRegQueries() { WmiFacade wmi = new WmiFacade(); wmi.Registry.GetInstalledPackageList(); }
public void TestStandardServiceOps() { WmiFacade wmi = new WmiFacade(); wmi.Service.Start("TestWinSvc"); }