static void SetBrightness(byte targetBrightness) { try { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); foreach (System.Management.ManagementObject o in moc) { o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise! break; //only work on the first object } moc.Dispose(); mos.Dispose(); } catch (Exception ex) { MessageBox.Show("8Brightness control is only supported on Laptops", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); Application.Exit(); } }
private void bnSelectPath_Click(object sender, RoutedEventArgs e) { TextBox tb = (sender == bnSelectAnswerPath) ? tbAnswerPath : (sender == tbTrackingPathLocal ? tbTrackingPathLocal : tbTrackingPathRemote); String newPath = FileDialogs.SelectFolder(tb.Text); if (newPath != null && System.IO.Path.IsPathRooted(newPath) && !newPath.StartsWith("\\\\")) { DriveInfo di = new DriveInfo(newPath.Substring(0, 2)); if (di.DriveType == DriveType.Network) { System.Management.SelectQuery sq = new System.Management.SelectQuery("Win32_LogicalDisk"); System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(sq); foreach (System.Management.ManagementObject drive in mos.Get()) { String path = drive.Path.ToString(); if (path.Contains(newPath.Substring(0, 2))) { System.Management.ManagementObject nwd = new System.Management.ManagementObject(drive.Path); UInt32 driveType = Convert.ToUInt32(nwd["DriveType"]); foreach (System.Management.PropertyData prop in nwd.Properties) { if (prop.Name == "ProviderName") { newPath = Convert.ToString(prop.Value) + newPath.Remove(0, 2); break; } } } } } tb.Text = newPath; } }
static void Main(string[] args) { if (FullDirPath == null) { System.Windows.Forms.MessageBox.Show("MotorControllerAllInOne.exe doesnt exist in\n" + Directory.GetCurrentDirectory()); } Console.WriteLine("Searching for kvaser driver..."); System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver"); query.Condition = "Name = 'kcanl'"; System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query); var drivers = searcher.Get(); try { if (drivers.Count <= 0) { ProcessStartInfo startInfo = new ProcessStartInfo(kanDriverEXE); startInfo.WorkingDirectory = FullDirPath; Process process = Process.Start(startInfo); process.WaitForExit(); } else { ProcessStartInfo runProg = new ProcessStartInfo(progEXE); runProg.WorkingDirectory = FullDirPath; Process.Start(runProg); return; } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); return; } }
public byte[] GetBrightnessLevels() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); //store result byte[] BrightnessLevels = new byte[0]; foreach (System.Management.ManagementObject o in moc) { BrightnessLevels = (byte[])o.GetPropertyValue("Level"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); return BrightnessLevels; }
/* * Get the array of allowed brightnesslevels for this system * */ static byte[] GetBrightnessLevels() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); byte[] BrightnessLevels = new byte[0]; try { System.Management.ManagementObjectCollection moc = mos.Get(); //store result foreach (System.Management.ManagementObject o in moc) { BrightnessLevels = (byte[])o.GetPropertyValue("Level"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); } catch (Exception) { Console.WriteLine("Sorry, Your System does not support this brightness control..."); } return BrightnessLevels; }
//get the actual percentage of brightness static int GetBrightness() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); //store result byte curBrightness = 0; foreach (System.Management.ManagementObject o in moc) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); return (int)curBrightness; }
static int GetBrightness() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); //store result byte curBrightness = 0; foreach (System.Management.ManagementObject o in moc) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); return((int)curBrightness); }
//array of valid brightness values in percent /// <summary> /// Gets the brightness levels. /// </summary> /// <returns>System.Byte[].</returns> public static byte[] GetBrightnessLevels() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); byte[] BrightnessLevels = new byte[0]; try { System.Management.ManagementObjectCollection moc = mos.Get(); //store result foreach (System.Management.ManagementObject o in moc) { BrightnessLevels = (byte[])o.GetPropertyValue("Level"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); } catch (Exception) { MessageBox.Show("Sorry, Your System does not support this brightness control..."); } return(BrightnessLevels); }
public Flashing(Printing printer) { _printer = printer; EmbeddedResourceHelper.ExtractResources(_resources); var query = new System.Management.SelectQuery("Win32_SystemDriver") { Condition = "Name = 'libusb0'" }; var searcher = new System.Management.ManagementObjectSearcher(query); var drivers = searcher.Get(); if (drivers.Count > 0) { printer.Print("libusb0 driver found on system", MessageType.Info); } else { printer.Print("libusb0 driver not found - attempting to install", MessageType.Info); if (Directory.Exists(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2"))) { Directory.Delete(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2"), true); } ZipFile.ExtractToDirectory(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2.zip"), Application.LocalUserAppDataPath); var size = 0; var success = Program.SetupCopyOEMInf(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2", "atmel_usb_dfu.inf"), "", Program.OemSourceMediaType.SpostNone, Program.OemCopyStyle.SpCopyNewer, null, 0, ref size, null); if (!success) { var errorCode = Marshal.GetLastWin32Error(); var errorString = new Win32Exception(errorCode).Message; printer.Print("Error: " + errorString, MessageType.Error); } } _process = new Process(); //process.EnableRaisingEvents = true; //process.OutputDataReceived += OnOutputDataReceived; //process.ErrorDataReceived += OnErrorDataReceived; _startInfo = new ProcessStartInfo { UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true, CreateNoWindow = true }; }
//get the actual percentage of brightness static int GetBrightness() { try { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); try { if (mos.Get().Count < 1) { Application.Exit(); } } catch (Exception e) { MessageBox.Show("Brightness control is only supported on Laptops", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); Environment.Exit(1); } //----------------------------------- unless it runs on laptop, it ends here RunAtStartup(); //store result byte curBrightness = 0; foreach (System.Management.ManagementObject o in moc) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); return((int)curBrightness); } catch (Exception ex) { MessageBox.Show("6Brightness control is only supported on Laptops", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(0); Application.Exit(); } }
static void Main(string[] args) { System.Management.SelectQuery sQuery = new System.Management.SelectQuery(string.Format("select name, startname from Win32_Service")); // where name = '{0}'", "MCShield.exe")); using (System.Management.ManagementObjectSearcher mgmtSearcher = new System.Management.ManagementObjectSearcher(sQuery)) { foreach (System.Management.ManagementObject service in mgmtSearcher.Get()) { string servicelogondetails = string.Format("Name: {0} , Logon : {1} ", service["Name"].ToString(), service["startname"]).ToString(); Console.WriteLine(servicelogondetails); } } Console.ReadLine(); }
public Flashing(Printing printer) { this.printer = printer; foreach (string resource in resources) { ExtractResource(resource); } System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver"); query.Condition = "Name = 'libusb0'"; System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query); var drivers = searcher.Get(); if (drivers.Count > 0) { printer.print("libusb0 driver found on system", MessageType.Info); } else { printer.print("libusb0 driver not found - attempting to install", MessageType.Info); if (Directory.Exists(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2"))) { Directory.Delete(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2"), true); } ZipFile.ExtractToDirectory(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2.zip"), Application.LocalUserAppDataPath); int size = 0; bool success = Program.SetupCopyOEMInf(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2", "atmel_usb_dfu.inf"), "", Program.OemSourceMediaType.SPOST_NONE, Program.OemCopyStyle.SP_COPY_NEWER, null, 0, ref size, null); if (!success) { var errorCode = Marshal.GetLastWin32Error(); var errorString = new Win32Exception(errorCode).Message; printer.print("Error: " + errorString, MessageType.Error); } } process = new System.Diagnostics.Process(); //process.EnableRaisingEvents = true; //process.OutputDataReceived += OnOutputDataReceived; //process.ErrorDataReceived += OnErrorDataReceived; startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.UseShellExecute = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true; startInfo.CreateNoWindow = true; }
private void button1_Click(object sender, EventArgs e) { //PropertyDataCollection properties = null; System.Management.ManagementObjectSearcher mox = null; System.Management.ManagementObjectCollection mok = null; try { //define scope (namespace) System.Management.ManagementScope x = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WMIACPI_IO"); //output current brightness mox = new System.Management.ManagementObjectSearcher(x, q); mok = mox.Get(); mok = mox.Get(); foreach (System.Management.ManagementObject o in mok) { byte[] curBytes = o.Properties["IOBytes"].Value as byte[]; curBytes[81] = 100; o.SetPropertyValue("IOBytes", curBytes); break; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); } finally { if (mox != null) { mox.Dispose(); } if (mok != null) { mok.Dispose(); } } }
static void Main(string[] args) { int wantBright = 100; try { Int32.TryParse(args[0], out wantBright); } catch { Console.WriteLine("Bad Argument. Must be a number."); Environment.Exit(1); } if (System.Environment.OSVersion.Platform == PlatformID.Unix) { foreach (var controller in Directory.GetDirectories("/sys/class/backlight/")) { int max_brightness; Int32.TryParse(File.ReadAllText(controller + "/max_brightness"), out max_brightness); int percent = max_brightness * wantBright; percent = percent / 100; try { File.WriteAllText(controller + "/brightness", percent.ToString()); } catch { Console.WriteLine("You may need to run this as sudo/root."); } } } else if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) { System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); foreach (System.Management.ManagementObject o in moc) { o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, wantBright }); break; } moc.Dispose(); mos.Dispose(); } }
private void SetBrightness(byte targetBrightness) { System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); foreach (System.Management.ManagementObject o in moc) { o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); break; } moc.Dispose(); mos.Dispose(); }
public void SetBrightness(int value) { byte targetBrightness = this._bLevels[value]; var s = new System.Management.ManagementScope("root\\WMI"); //define scope (namespace) var q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); // define query var mos = new System.Management.ManagementObjectSearcher(s, q); // output current brightness var moc = mos.Get(); foreach (System.Management.ManagementObject o in moc) { o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); // note the reversed order - won't work otherwise! break; //only work on the first object } moc.Dispose(); mos.Dispose(); }
public void setBrightness(byte targetBrightness) { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); foreach (System.Management.ManagementObject o in moc) { o.InvokeMethod("WmiSetBrightness", new Object[] { Int32.MaxValue, targetBrightness}); //note the reversed order - won't work otherwise! break; //only work on the first object } moc.Dispose(); mos.Dispose(); }
/* * private void askForWindowCloseConfirmation(int number) * { * acceptingVoiceInput = false; * * t.Speak(Properties.Settings.Default.voiceCallClient + ", tem a certeza que pretende fechar a " + number + "ª janela?"); * * acceptingVoiceInput = true; * awaitingConfirmation = true; * awaitingWindowCloseConfirmation = true; * } * * private void closeWindow(int number) * { * Process[] processList = Array.FindAll(Process.GetProcesses(), process => !String.IsNullOrEmpty(process.MainWindowTitle)); * if (!processList[number - 1].HasExited) * processList[number - 1].CloseMainWindow(); * } * * [DllImport("user32.dll")] * internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); * * private void minimizeWindow(int number) * { * int MINIMIZE = 6; * * Process[] processList = Array.FindAll(Process.GetProcesses(), process => !String.IsNullOrEmpty(process.MainWindowTitle)); * ShowWindow(processList[number - 1].MainWindowHandle, MINIMIZE); * } * * private void maximizeWindow(int number) * { * int MAXIMIZE = 3; * * Process[] processList = Array.FindAll(Process.GetProcesses(), process => !String.IsNullOrEmpty(process.MainWindowTitle)); * ShowWindow(processList[number - 1].MainWindowHandle, MAXIMIZE); * } */ private int GetBrightness() { System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); byte curBrightness = 0; foreach (System.Management.ManagementObject o in moc) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; } moc.Dispose(); mos.Dispose(); return((int)curBrightness); }
static int GetBrightness() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); System.Management.ManagementObjectCollection moc = mos.Get(); //store result byte curBrightness = 0; /// /// 远程登陆的时候这会出错!!! try { foreach (System.Management.ManagementObject o in moc) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; //only work on the first object } } catch (Exception ex) { //MessageBox.Show(ex.StackTrace, ex.Message); return(-1); } finally { moc.Dispose(); mos.Dispose(); } return(curBrightness); }
/// <summary> /// get the actual percentage of brightness /// </summary> /// <returns></returns> public int GetBrightness() { var s = new System.Management.ManagementScope("root\\WMI"); //define scope (namespace) var q = new System.Management.SelectQuery("WmiMonitorBrightness"); // define query var mos = new System.Management.ManagementObjectSearcher(s, q); // output current brightness var moc = mos.Get(); byte curBrightness = 0; foreach (System.Management.ManagementObject o in moc) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); var i = Array.IndexOf(this._bLevels, curBrightness); return(i < 0 ? 1 : i); }
static void SetBrightness(byte targetBrightness) { //define scope (namespace) System.Management.ManagementScope x = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); //output current brightness System.Management.ManagementObjectSearcher mox = new System.Management.ManagementObjectSearcher(x, q); System.Management.ManagementObjectCollection mok = mox.Get(); foreach (System.Management.ManagementObject o in mok) { o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise! break; //only work on the first object } mox.Dispose(); mok.Dispose(); }
//funcion interna que obtiene el process ID del servicio mediante el DLL private ServiciosClass obtenerServicio(string nombreServicio) { ServiciosClass servicio = new ServiciosClass(); System.Management.SelectQuery consulta = new System.Management.SelectQuery(string.Format("select processid, startname from Win32_Service where name = '{0}'", nombreServicio)); System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(consulta); foreach (System.Management.ManagementObject servicioController in searcher.Get()) { try { servicio.Id = servicioController["PROCESSID"].ToString(); servicio.UsuarioServicio = servicioController["STARTNAME"].ToString(); } catch (Exception) { servicio.Id = string.Empty; servicio.UsuarioServicio = "Acceso Denegado"; } } return(servicio); }
// Set's brightness of all screens public static void SetBrightness(byte percentage) { // Define scope (namespace) System.Management.ManagementScope scope = new System.Management.ManagementScope("root\\WMI"); // Define query System.Management.SelectQuery query = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); // Get brightness methods using (System.Management.ManagementObjectSearcher objectSearcher = new System.Management.ManagementObjectSearcher(scope, query)) using (System.Management.ManagementObjectCollection objectCollection = objectSearcher.Get()) { // Store result foreach (System.Management.ManagementObject o in objectCollection) { // Object is made out of (delayTime, newPercentage) o.InvokeMethod("WmiSetBrightness", new Object[] { 0, percentage }); //break; // Only act on first object } } }
/** * Look for any currently installed printers that were installed through this Service, but are no longer in the printers list file. Those printers should * be removed from the system. * * @param List<string> A list of currently installed printer names that were installed through this Service * */ void DeletePrinters(List <string> installedPrinters) { // For each printer in the installed List<> if it is NOT in the printers list, delete it List <string> lPrinters = new List <string>(); if (File.Exists(working_directory)) { System.IO.StreamReader file = new System.IO.StreamReader(working_directory); string line; while ((line = file.ReadLine()) != null) { lPrinters.Add(line); } file.Close(); } foreach (string iPrinter in installedPrinters) { if (!lPrinters.Contains(iPrinter)) { // Delete System.Management.ManagementScope oManagementScope = new System.Management.ManagementScope(System.Management.ManagementPath.DefaultPath); oManagementScope.Connect(); System.Management.SelectQuery query = new System.Management.SelectQuery("SELECT * FROM Win32_Printer"); System.Management.ManagementObjectSearcher search = new System.Management.ManagementObjectSearcher(oManagementScope, query); System.Management.ManagementObjectCollection printers = search.Get(); foreach (System.Management.ManagementObject printer in printers) { string pName = printer["Name"].ToString().ToLower(); if (pName.Equals(iPrinter.ToLower())) { printer.Delete(); break; } } } } }
/// <summary> /// Yüklü olan Cd ROM ların bilgisini getiren method. /// </summary> /// <returns>Yüklü olan Cd ROM ların bilgisini Sürücü İsmi:volumename; /// \nSürücü Seri No:volumeserialnumber; formatında getirir.</returns> public List <String> YukluCDROMBilgileri() { List <string> cdProperties = new List <string>(); //create a query to searech the system for a drive type of 5 (CDROM) System.Management.SelectQuery query = new System.Management.SelectQuery("select * from win32_logicaldisk where drivetype=5"); //use the System.Management Namespace to execute the query using the //ManagementObjectSearcher Object System.Management.ManagementObjectSearcher moSearcher = new System.Management.ManagementObjectSearcher(query); //now loop through all items returned from the query foreach (System.Management.ManagementObject drives in moSearcher.Get()) { //check for a volumename and serial number property if ((drives["volumename"] != null) && (drives["volumeserialnumber"] != null)) { cdProperties.Add(String.Format("Sürücü İsmi:{0};\nSürücü Seri No:{1};", drives["volumename"].ToString(), drives["volumeserialnumber"].ToString())); } } return(cdProperties); }
//array of valid brightness values in percent static byte[] GetBrightnessLevels() { //define scope (namespace) System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI"); //define query System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness"); //output current brightness System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q); byte[] BrightnessLevels = new byte[0]; try { System.Management.ManagementObjectCollection moc = mos.Get(); //store result foreach (System.Management.ManagementObject o in moc) { BrightnessLevels = (byte[])o.GetPropertyValue("Level"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); } catch (Exception ex) { MessageBox.Show("7Brightness control is only supported on Laptops", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); Application.Exit(); } return(BrightnessLevels); }
/// <summary> /// array of valid brightness values in percent /// </summary> /// <returns></returns> private byte[] getBrightnessLevels() { var s = new System.Management.ManagementScope("root\\WMI"); //define scope (namespace) var q = new System.Management.SelectQuery("WmiMonitorBrightness"); // define query var mos = new System.Management.ManagementObjectSearcher(s, q); // output current brightness var brightnessLevels = new byte[0]; try { var moc = mos.Get(); foreach (System.Management.ManagementObject o in moc) { brightnessLevels = (byte[])o.GetPropertyValue("Level"); break; //only work on the first object } moc.Dispose(); mos.Dispose(); } catch { } return(brightnessLevels); }
/// <summary> /// Uses ServiceController. /// </summary> public void ExecuteWindows() { System.Management.SelectQuery sQuery = new System.Management.SelectQuery("select * from Win32_Service"); // where name = '{0}'", "MCShield.exe")); using System.Management.ManagementObjectSearcher mgmtSearcher = new System.Management.ManagementObjectSearcher(sQuery); foreach (System.Management.ManagementObject service in mgmtSearcher.Get()) { try { var val = service.GetPropertyValue("Name").ToString(); if (val != null) { var obj = new ServiceObject(val); val = service.GetPropertyValue("AcceptPause")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.AcceptPause = bool.Parse(val); } val = service.GetPropertyValue("AcceptStop")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.AcceptStop = bool.Parse(val); } obj.Caption = service.GetPropertyValue("Caption")?.ToString(); val = service.GetPropertyValue("CheckPoint")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.CheckPoint = uint.Parse(val, CultureInfo.InvariantCulture); } obj.CreationClassName = service.GetPropertyValue("CreationClassName")?.ToString(); val = service.GetPropertyValue("DelayedAutoStart")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.DelayedAutoStart = bool.Parse(val); } obj.Description = service.GetPropertyValue("Description")?.ToString(); val = service.GetPropertyValue("DesktopInteract")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.DesktopInteract = bool.Parse(val); } obj.DisplayName = service.GetPropertyValue("DisplayName")?.ToString(); obj.ErrorControl = service.GetPropertyValue("ErrorControl")?.ToString(); val = service.GetPropertyValue("ExitCode")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.ExitCode = uint.Parse(val, CultureInfo.InvariantCulture); } if (DateTime.TryParse(service.GetPropertyValue("InstallDate")?.ToString(), out DateTime dateTime)) { obj.InstallDate = dateTime; } obj.PathName = service.GetPropertyValue("PathName")?.ToString(); val = service.GetPropertyValue("ProcessId")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.ProcessId = uint.Parse(val, CultureInfo.InvariantCulture); } val = service.GetPropertyValue("ServiceSpecificExitCode")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.ServiceSpecificExitCode = uint.Parse(val, CultureInfo.InvariantCulture); } obj.ServiceType = service.GetPropertyValue("ServiceType")?.ToString(); val = service.GetPropertyValue("Started").ToString(); if (!string.IsNullOrEmpty(val)) { obj.Started = bool.Parse(val); } obj.StartMode = service.GetPropertyValue("StartMode")?.ToString(); obj.StartName = service.GetPropertyValue("StartName")?.ToString(); obj.State = service.GetPropertyValue("State")?.ToString(); obj.Status = service.GetPropertyValue("Status")?.ToString(); obj.SystemCreationClassName = service.GetPropertyValue("SystemCreationClassName")?.ToString(); obj.SystemName = service.GetPropertyValue("SystemName")?.ToString(); val = service.GetPropertyValue("TagId")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.TagId = uint.Parse(val, CultureInfo.InvariantCulture); } val = service.GetPropertyValue("WaitHint")?.ToString(); if (!string.IsNullOrEmpty(val)) { obj.WaitHint = uint.Parse(val, CultureInfo.InvariantCulture); } Results.Enqueue(obj); } } catch (Exception e) when( e is TypeInitializationException || e is PlatformNotSupportedException) { Log.Warning(Strings.Get("CollectorNotSupportedOnPlatform"), GetType().ToString()); } } foreach (var file in DirectoryWalker.WalkDirectory("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Startup")) { var name = file.Split(Path.DirectorySeparatorChar)[^ 1];
/// <summary> /// Uses ServiceController. /// </summary> public void ExecuteWindows() { System.Management.SelectQuery sQuery = new System.Management.SelectQuery("select * from Win32_Service"); // where name = '{0}'", "MCShield.exe")); using (System.Management.ManagementObjectSearcher mgmtSearcher = new System.Management.ManagementObjectSearcher(sQuery)) { foreach (System.Management.ManagementObject service in mgmtSearcher.Get()) { var obj = new ServiceObject(); if (service["AcceptPause"] != null) { obj.AcceptPause = bool.Parse(service["AcceptPause"].ToString()); } if (service["AcceptStop"] != null) { obj.AcceptStop = bool.Parse(service["AcceptStop"].ToString()); } if (service["Caption"] != null) { obj.Caption = service["Caption"].ToString(); } if (service["CheckPoint"] != null) { obj.CheckPoint = uint.Parse(service["CheckPoint"].ToString(), CultureInfo.InvariantCulture); } if (service["CreationClassName"] != null) { obj.CreationClassName = service["CreationClassName"].ToString(); } if (service["DelayedAutoStart"] != null) { obj.DelayedAutoStart = bool.Parse(service["DelayedAutoStart"].ToString()); } if (service["Description"] != null) { obj.Description = service["Description"].ToString(); } if (service["DesktopInteract"] != null) { obj.DesktopInteract = bool.Parse(service["DesktopInteract"].ToString()); } if (service["DisplayName"] != null) { obj.DisplayName = service["DisplayName"].ToString(); } if (service["ErrorControl"] != null) { obj.ErrorControl = service["ErrorControl"].ToString(); } if (service["ExitCode"] != null) { obj.ExitCode = uint.Parse(service["ExitCode"].ToString(), CultureInfo.InvariantCulture); } if (service["InstallDate"] != null) { obj.InstallDate = service["InstallDate"].ToString(); } if (service["Name"] != null) { obj.Name = service["Name"].ToString(); } if (service["PathName"] != null) { obj.PathName = service["PathName"].ToString(); } if (service["ProcessId"] != null) { obj.ProcessId = uint.Parse(service["ProcessId"].ToString(), CultureInfo.InvariantCulture); } if (service["ServiceSpecificExitCode"] != null) { obj.ServiceSpecificExitCode = uint.Parse(service["ServiceSpecificExitCode"].ToString(), CultureInfo.InvariantCulture); } if (service["ServiceType"] != null) { obj.ServiceType = service["ServiceType"].ToString(); } if (service["Started"] != null) { obj.Started = bool.Parse(service["Started"].ToString()); } if (service["StartMode"] != null) { obj.StartMode = service["StartMode"].ToString(); } if (service["StartName"] != null) { obj.StartName = service["StartName"].ToString(); } if (service["State"] != null) { obj.State = service["State"].ToString(); } if (service["Status"] != null) { obj.Status = service["Status"].ToString(); } if (service["SystemCreationClassName"] != null) { obj.SystemCreationClassName = service["SystemCreationClassName"].ToString(); } if (service["SystemName"] != null) { obj.SystemName = service["SystemName"].ToString(); } if (service["TagId"] != null) { obj.TagId = uint.Parse(service["TagId"].ToString(), CultureInfo.InvariantCulture); } if (service["WaitHint"] != null) { obj.WaitHint = uint.Parse(service["WaitHint"].ToString(), CultureInfo.InvariantCulture); } DatabaseManager.Write(obj, this.RunId); } } }