public ClevoFanControlService() { InitializeComponent(); //Initiate CoreTempInfo class. coreTempInfo = new CoreTempInfo(); //Sign up for an event reporting errors coreTempInfo.ReportError += new ErrorOccured(CTInfo_ReportError); string Namespace = @"root\WMI"; string className = "CLEVO_GET"; CimInstance clevo = new CimInstance(className, Namespace); CimSession mySession = CimSession.Create("localhost"); CimInstance searchInstance = mySession.GetInstance(Namespace, clevo); // Set up a timer to trigger every minute. eventTimer = new Timer { Interval = 1000 // 60 seconds }; eventTimer.Elapsed += new ElapsedEventHandler(this.OnTimer); eventTimer.Start(); if (!Directory.Exists(clevoAppData)) { Directory.CreateDirectory(clevoAppData); } }
static void ReadFile(CimSession session, string file) { // https://twitter.com/mattifestation/status/1220713684756049921 CimInstance baseInstance = new CimInstance("PS_ModuleFile"); baseInstance.CimInstanceProperties.Add(CimProperty.Create("InstanceID", file, CimFlags.Key)); CimInstance modifiedInstance = session.GetInstance("ROOT/Microsoft/Windows/Powershellv3", baseInstance); System.Byte[] fileBytes = (byte[])modifiedInstance.CimInstanceProperties["FileData"].Value; Console.WriteLine(Encoding.UTF8.GetString(fileBytes, 0, fileBytes.Length)); }
/* * "function Decode {If ($args[0] -is [System.Array]) {[System.Text.Encoding]::ASCII.GetString($args[0])} * Else {\"Not Found\"}} * * * $Monitors = Get-CimInstance WmiMonitorID -Namespace root\\wmi; * ForEach ($Monitor in $monitors) {$Serial = Decode $Monitor.SerialNumberID -notmatch 0; if($Serial -ne 0){return $Serial}}"); */ static void Main(string[] args) { Console.WriteLine("Hello World!"); string Namespace = @"root\wmi"; string className = "WmiMonitorID"; CimInstance myDrive = new CimInstance(className, Namespace); //myDrive.CimInstanceProperties.Add(CimProperty.Create("SerialNumberID", null, CimFlags.Key)); //CimProperty.Create("SerialNumberID", "C:", CimFlags.Key)); CimSession mySession = CimSession.Create(null); CimInstance searchInstance = mySession.GetInstance(Namespace, myDrive); IEnumerable <CimInstance> queryInstances = mySession.QueryInstances(@"root\wmi", "WQL", @"select * from WmiMonitorID"); }
public static void GetInstanceSync(CimSession cimSession, string cimNamespace, string cimClassName) { // Check Arguments if (cimNamespace == null) { throw new ArgumentNullException("cimNamespace"); } if (cimClassName == null) { throw new ArgumentNullException("cimClassName"); } try { CimInstance getInstance = GetInstanceCore(cimSession, cimNamespace, cimClassName); if (getInstance == null) { Console.WriteLine("Operation GetInstance not performed"); return; } CimInstance cimInstance = cimSession.GetInstance(cimNamespace, getInstance); // Use the instance PrintCimInstance(cimInstance); } catch (CimException ex) { PrintCimException(ex); } catch (Exception ex) { Console.WriteLine(ex.Message); } }