public static byte 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(curBrightness); }
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 { throw new NotSupportedException("This application is not supported on this system!"); } return(BrightnessLevels); }
static AndroidUsbDriverHelper( ) { try { System.Management.ManagementClass wmi = new System.Management.ManagementClass ( ); System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery ( QUERY ); System.Management.ManagementScope oMs = new System.Management.ManagementScope ( ); System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher ( oMs, oQuery ); System.Management.ManagementObjectCollection oResults = oSearcher.Get ( ); if ( oResults.Count == 1 ) { foreach ( var item in oResults ) { string dv = string.Format ( CultureInfo.InvariantCulture, "{0}", item["DriverVersion"] ); if ( !string.IsNullOrEmpty ( dv ) ) { DriverVersion = new Version ( dv ); } else { // default DriverVersion = new Version ( "0.0.0.0" ); } string cg = string.Format ( CultureInfo.InvariantCulture, "{0}", item["ClassGuid"] ); if ( !string.IsNullOrEmpty ( cg ) ) { IsRevision2Driver = string.Compare ( cg, DRIVER_CLASS_GUID_REVISION2, true ) == 0; IsRevision1Driver = !IsRevision2Driver; } else { // default to cupcake IsRevision1Driver = true; IsRevision2Driver = false; } } } } catch ( Exception ex ) { Logger.LogError ( typeof ( AndroidUsbDriverHelper ), ex.Message, ex ); DriverVersion = new Version ( "0.0.0.0" ); } }
// Returns brightness of first screen public static int GetBrightnes() { int curBrightness = 0; // Define scope (namespace) System.Management.ManagementScope scope = new System.Management.ManagementScope("root\\WMI"); // Define query System.Management.SelectQuery query = new System.Management.SelectQuery("WmiMonitorBrightness"); // Get current brightness 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) { curBrightness = (byte)o.GetPropertyValue("CurrentBrightness"); break; // Return brightness of first object } } return(curBrightness); }
public static Size GetMaximumScreenSizePrimary() { var scope = new System.Management.ManagementScope(); var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution"); UInt32 maxHResolution; UInt32 maxVResolution; using (var searcher = new System.Management.ManagementObjectSearcher(scope, q)) { var results = searcher.Get(); maxHResolution = 0; maxVResolution = 0; foreach (var item in results) { if ((UInt32)item["HorizontalResolution"] > maxHResolution) maxHResolution = (UInt32)item["HorizontalResolution"]; if ((UInt32)item["VerticalResolution"] > maxVResolution) maxVResolution = (UInt32)item["VerticalResolution"]; } } return new Size((int)maxHResolution, (int)maxVResolution); }
//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; }
public void ausfuehrungdeinstallation(string workstationname, string username, string password, bool durchfuehren, int msgboxjaneinvalue) { if (durchfuehren && msgboxjaneinvalue == 2) { this.unauthorised = false; this.authorized = true; var connection = new System.Management.ConnectionOptions(); connection.Username = username; //auskommentieren, wenn der Rechnername 127.0.0.1 ist. connection.Password = password; //auskommentieren, wenn der Rechnername 127.0.0.1 ist. //Ausfuehrung der PMI.exe ohne Benutzerinteraktion object[] theProcessToRun1 = { @"C:\PMI.exe /uninstall /quiet /norestart /log C:\log.txt" }; //uninstall PMI silently var wmiScope = new System.Management.ManagementScope(@"\\" + workstationname + @"\root\cimv2", connection); try { wmiScope.Connect(); using (var managementClass = new System.Management.ManagementClass(wmiScope, new System.Management.ManagementPath("Win32_Process"), new System.Management.ObjectGetOptions())) { managementClass.InvokeMethod("Create", theProcessToRun1); } } catch (System.UnauthorizedAccessException) { this.unauthorised = true; this.authorized = false; } } }
internal static byte[] GetDmi() { var scope = new System.Management.ManagementScope("\\\\" + "." + "\\root\\WMI"); scope.Connect(); var wmiquery = new System.Management.ObjectQuery("SELECT * FROM MSSmBios_RawSMBiosTables"); var searcher = new System.Management.ManagementObjectSearcher(scope, wmiquery); var coll = searcher.Get(); var M_ByMajorVersion = 0; var M_ByMinorVersion = 0; byte[] data = null; foreach (var O in coll) { var queryObj = (System.Management.ManagementObject)O; if (queryObj["SMBiosData"] != null) { data = (byte[])(queryObj["SMBiosData"]); } if (queryObj["SmbiosMajorVersion"] != null) { M_ByMajorVersion = (byte)(queryObj["SmbiosMajorVersion"]); } if (queryObj["SmbiosMinorVersion"] != null) { M_ByMinorVersion = (byte)(queryObj["SmbiosMinorVersion"]); } //if (queryObj["Size"] != null) m_dwLen = (long)(queryObj["Size"]); //m_dwLen = m_pbBIOSData.Length; } Version = (ushort)(M_ByMajorVersion << 8 | M_ByMinorVersion); return(data); }
/* * 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; }
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(); } }
//array of valid brightness values in percent 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 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; }
public static ActionResult GetAndroidUsbDriverVersionWmi(Session session) { session.Log("(DECA) Begin GetAndroidUsbDriverVersionWmi"); try { System.Management.ManagementClass wmi = new System.Management.ManagementClass( ); System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery(string.Format(CultureInfo.InvariantCulture, WMI_QUERY, REVISION2_GUID)); System.Management.ManagementScope oMs = new System.Management.ManagementScope( ); System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher(oMs, oQuery); System.Management.ManagementObjectCollection oResults = oSearcher.Get( ); if (oResults.Count > 0) { foreach (var item in oResults) { string cg = string.Format(CultureInfo.InvariantCulture, "{0}", item["ClassGuid"]); if (!string.IsNullOrEmpty(cg)) { bool foundR1 = string.Compare(cg, REVISION1_GUID, true) == 0; bool foundR2 = string.Compare(cg, REVISION2_GUID, true) == 0; if (foundR1) { session[ANDROIDUSBDRIVERVERSION] = REVISION1; session[ANDROIDUSBDRIVERSINSTALLED] = "1"; session.Log("(DECA) Found Revision 1 version of Android USB Driver"); return(ActionResult.Success); } else if (foundR2) { session[ANDROIDUSBDRIVERVERSION] = REVISION2; session[ANDROIDUSBDRIVERSINSTALLED] = "0"; session.Log("(DECA) Found Revision 2 version of Android USB Driver"); return(ActionResult.Success); } else { session.Log("(DECA) Did not find a know ClassGuid: {0}", cg); } } else { session.Log("(DECA) ClassGuid was Empty"); } } } else { session.Log("(DECA) No WMI Results were returned."); } } catch (Exception ex) { session.Log(ex.ToString()); } session[ANDROIDUSBDRIVERVERSION] = "0"; session[ANDROIDUSBDRIVERSINSTALLED] = "0"; session.Log("(DECA) Did not find any version of Android USB Driver"); return(ActionResult.Success); }
//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(); } }
private void LoginButton_Click(object sender, System.EventArgs e) { bool success = false; if (this.MachineNameTextBox.Text == string.Empty) { this.MachineNameTextBox.Text = @"\\localhost\root\cimv2"; } else { if (!this.MachineNameTextBox.Text.StartsWith(@"\\")) { this.MachineNameTextBox.Text = @"\\" + this.MachineNameTextBox.Text; } } if (!this.MachineNameTextBox.Text.StartsWith(@"\\localhost")) { if (this.UsernameTextBox.Text != string.Empty && this.PasswordTextBox.Text != string.Empty && this.MachineNameTextBox.Text != string.Empty) { try { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = this.UsernameTextBox.Text; oConn.Password = this.PasswordTextBox.Text; oConn.Impersonation = System.Management.ImpersonationLevel.Impersonate; //oConn.Authority = this.MachineNameTextBox.Text; oConn.Authentication = System.Management.AuthenticationLevel.Connect; System.Management.ManagementScope oMs = new System.Management.ManagementScope(this.MachineNameTextBox.Text, oConn); oMs.Path = new System.Management.ManagementPath(this.MachineNameTextBox.Text); oMs.Connect(); success = oMs.IsConnected; } catch (Exception exc) { Terminals.Logging.Info("Login Failed", exc); MessageBox.Show(exc.Message); } if (success) { this.Cancelled = false; this.Visible = false; } } } else { this.Cancelled = false; this.Visible = false; } }
/// <summary> /// Looks for the resolution 5760 x 1080. If the resolution is available, stereo mode is available. /// (Looking for the max resolution didn't work because it returned 5760 x 1200.) /// </summary> /// <returns></returns> public static void PrintResolutions() { var scope = new System.Management.ManagementScope(); var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution"); using(var searcher = new System.Management.ManagementObjectSearcher(scope, q)) { var results = searcher.Get(); foreach(var item in results) { Console.WriteLine((UInt32)item["HorizontalResolution"] + " x " + (UInt32)item["VerticalResolution"]); } } }
private void CreateWmiDataProviderFromWmiItem(wmi_item wmiItem) { if (this.WmiDataProvider == null) { var wmiNamespace = String.Format(@"{0}\{1}", this.TargetInfo.GetAddress(), [email protected]); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); this.WmiDataProvider = new WmiDataProvider(wmiManagementScope); } }
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(); } } }
public static string Detect3264() { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); System.Management.ManagementScope oMs = new System.Management.ManagementScope("\\\\localhost", oConn); System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select AddressWidth from Win32_Processor"); System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher(oMs, oQuery); System.Management.ManagementObjectCollection oReturnCollection = oSearcher.Get(); string addressWidth = null; foreach (System.Management.ManagementObject oReturn in oReturnCollection) { addressWidth = oReturn["AddressWidth"].ToString(); } return addressWidth; }
private WmiDataProvider GetWmiDataProvider(string @namespace) { if (this.WmiDataProvider != null) { return(this.WmiDataProvider); } var wmiNamespace = String.Format(@"\\{0}\{1}", this.TargetInfo.GetAddress(), @namespace); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); return(new WmiDataProvider(wmiManagementScope)); }
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(); } }
/// <summary> /// Looks for the resolution 5760 x 1080. If the resolution is available, stereo mode is available. /// (Looking for the max resolution didn't work because it returned 5760 x 1200.) /// </summary> /// <returns></returns> public static bool IsStereoAvailable() { bool isStereoModeAvailable = false; var scope = new System.Management.ManagementScope(); var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution"); using(var searcher = new System.Management.ManagementObjectSearcher(scope, q)) { var results = searcher.Get(); foreach(var item in results) { if((UInt32)item["HorizontalResolution"] == 5760 && (UInt32)item["VerticalResolution"] == 1080) isStereoModeAvailable = true; } } return isStereoModeAvailable; }
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(); }
private void vInitializeRegistryToInteractWithDesktop() { try { System.Management.ConnectionOptions coOptions = new System.Management.ConnectionOptions(); coOptions.Impersonation = System.Management.ImpersonationLevel.Impersonate; System.Management.ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions); mgmtScope.Connect(); System.Management.ManagementObject wmiService; wmiService = new System.Management.ManagementObject("Win32_Service.Name='" + mdlConstantes.clsConstantes.WINDOWSSERVICE_SISCOMENSAGEM_NAME + "'"); System.Management.ManagementBaseObject InParam = wmiService.GetMethodParameters("Change"); InParam["DesktopInteract"] = true; System.Management.ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null); } catch { // Cant access the registry } }
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(); }
static AndroidUsbDriverHelper( ) { try { System.Management.ManagementClass wmi = new System.Management.ManagementClass( ); System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery(QUERY); System.Management.ManagementScope oMs = new System.Management.ManagementScope( ); System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher(oMs, oQuery); System.Management.ManagementObjectCollection oResults = oSearcher.Get( ); if (oResults.Count == 1) { foreach (var item in oResults) { string dv = string.Format(CultureInfo.InvariantCulture, "{0}", item["DriverVersion"]); if (!string.IsNullOrEmpty(dv)) { DriverVersion = new Version(dv); } else { // default DriverVersion = new Version("0.0.0.0"); } string cg = string.Format(CultureInfo.InvariantCulture, "{0}", item["ClassGuid"]); if (!string.IsNullOrEmpty(cg)) { IsRevision2Driver = string.Compare(cg, DRIVER_CLASS_GUID_REVISION2, true) == 0; IsRevision1Driver = !IsRevision2Driver; } else { // default to cupcake IsRevision1Driver = true; IsRevision2Driver = false; } } } } catch (Exception ex) { Logger.LogError(typeof(AndroidUsbDriverHelper), ex.Message, ex); DriverVersion = new Version("0.0.0.0"); } }
/* * 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); }
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(); }
/// <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); }
// 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> /// 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); }
public static int[] GetMaxScreenSize() { var scope = new System.Management.ManagementScope(); var q = new System.Management.ObjectQuery("SELECT * FROM CIM_VideoControllerResolution"); var searcher = new System.Management.ManagementObjectSearcher(scope, q); var results = searcher.Get(); UInt32 maxHResolution = 0; UInt32 maxVResolution = 0; foreach (var item in results) { if ((UInt32)item["HorizontalResolution"] > maxHResolution) { maxHResolution = (UInt32)item["HorizontalResolution"]; } if ((UInt32)item["VerticalResolution"] > maxVResolution) { maxVResolution = (UInt32)item["VerticalResolution"]; } } return(new int[2] { Convert.ToInt32(maxHResolution), Convert.ToInt32(maxVResolution) }); }
//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); }
private static void StopAppPool(string pPoolName, bool DoRestart) { try { System.Management.ManagementScope scope = new System.Management.ManagementScope("root\\MicrosoftIISv2"); scope.Connect(); System.Management.ManagementObject appPool = new System.Management.ManagementObject(scope, new System.Management.ManagementPath("IIsApplicationPool.Name='W3SVC/AppPools/" + pPoolName + "'"), null); if (appPool != null) { if (DoRestart) { appPool.InvokeMethod("Recycle", null, null); } else { appPool.InvokeMethod("Stop", null, null); } } } catch (Exception ee) { StartupLog($"IIS Shutdown problem : {ee}"); } }
private void LoadShares(string Username, string Password, string Computer) { List<Share> shares = new List<Share>(); System.Text.StringBuilder sb = new StringBuilder(); string qry = "select * from win32_share"; System.Management.ManagementObjectSearcher searcher; System.Management.ObjectQuery query = new System.Management.ObjectQuery(qry); if(Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = Username; oConn.Password = Password; if(!Computer.StartsWith(@"\\")) Computer = @"\\" + Computer; if(!Computer.ToLower().EndsWith(@"\root\cimv2")) Computer = Computer + @"\root\cimv2"; System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn); searcher = new System.Management.ManagementObjectSearcher(oMs, query); } else { searcher = new System.Management.ManagementObjectSearcher(query); } foreach(System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); foreach(System.Management.PropertyData p in share.Properties) { switch(p.Name) { case "AccessMask": if(p.Value != null) s.AccessMask = p.Value.ToString(); break; case "MaximumAllowed": if(p.Value != null) s.MaximumAllowed = p.Value.ToString(); break; case "InstallDate": if(p.Value != null) s.InstallDate = p.Value.ToString(); break; case "Description": if(p.Value != null) s.Description = p.Value.ToString(); break; case "Caption": if(p.Value != null) s.Caption = p.Value.ToString(); break; case "AllowMaximum": if(p.Value != null) s.AllowMaximum = p.Value.ToString(); break; case "Name": if(p.Value != null) s.Name = p.Value.ToString(); break; case "Path": if(p.Value != null) s.Path = p.Value.ToString(); break; case "Status": if(p.Value != null) s.Status = p.Value.ToString(); break; case "Type": if(p.Value != null) s._Type = p.Value.ToString(); break; default: break; } } shares.Add(s); } this.dataGridView1.DataSource = shares; }
/// <summary> /// SQL数据库备份 /// </summary> /// <param name="path">备份到的路径< /param> /// <param name="Backup_PercentComplete">进度</param> /// <param name="oBackup">数据库备份服务对象</param> /// <param name="remark">备份备注</param> public static bool SQLDbBackup(string path, SQLDMO.BackupSink_PercentCompleteEventHandler Backup_PercentComplete, out SQLDMO.Backup oBackup, string remark = null) { SqlConnectionStringBuilder connStrBuilder = new SqlConnectionStringBuilder(TopFashion.Configs.ConnString); string ServerIP = connStrBuilder.DataSource; string LoginUserName = connStrBuilder.UserID; string LoginPass = connStrBuilder.Password; string DBName = connStrBuilder.InitialCatalog; string dir = path + "\\" + DBName; dir = dir.Replace("\\\\", "\\"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string locale = string.Empty; string username = string.Empty; string password = string.Empty; string authority = string.Empty; string RemoteAuth = TopFashion.Configs.RemoteAuth; if (!string.IsNullOrEmpty(RemoteAuth)) { string[] ra = RemoteAuth.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (ra.Length == 4) { locale = ra[0]; username = ra[1]; password = ra[2]; authority = ra[3]; } } System.Management.ManagementScope scope = new System.Management.ManagementScope("\\\\" + ServerIP + "\\root\\cimv2", new System.Management.ConnectionOptions(locale, username, password, authority, System.Management.ImpersonationLevel.Impersonate, System.Management.AuthenticationLevel.Default, true, null, TimeSpan.MaxValue)); if (ServerIP == "." || ServerIP == "(local)" || ServerIP == "127.0.0.1") { } else { int i = WmiShareRemote.CreateRemoteDirectory(scope, Path.GetDirectoryName(dir), Directory.GetParent(dir).FullName); } string DBFile = DBName + DateTime.Now.ToString("yyyyMMddHHmm"); string filename = dir + "\\" + DBFile + ".bak"; if (!File.Exists(filename)) { try { FileStream fs = File.Create(filename); fs.Close(); } catch (Exception e) { TopFashion.WriteLog.CreateLog("数据库操作", "SQLDbBackup", "error", "无法创建 [" + filename + "] 数据库备份文件!" + Environment.NewLine + e.Message); } } if (ServerIP == "." || ServerIP == "(local)" || ServerIP == "127.0.0.1") { } else { bool flag = WmiShareRemote.WmiFileCopyToRemote(ServerIP, username, password, dir, "DatabaseBackup", "数据库备份集", null, new string[] { filename }, 0); } oBackup = new SQLDMO.BackupClass(); SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass(); try { oSQLServer.LoginSecure = false; oSQLServer.Connect(ServerIP, LoginUserName, LoginPass); oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database; oBackup.PercentComplete += Backup_PercentComplete; oBackup.Database = DBName; oBackup.Files = @"" + string.Format("[{0}]", filename) + ""; oBackup.BackupSetName = DBName; oBackup.BackupSetDescription = "备份集" + DBName; oBackup.Initialize = true; oBackup.SQLBackup(oSQLServer);//这里可能存在问题:比如备份远程数据库的时候,选的路径path却是本地的,恰好是远程服务器上不存在的目录 TopFashion.SQLDBHelper SqlHelper = new TopFashion.SQLDBHelper(); SqlHelper.ExecuteSql("insert into Record (DB, Path, Remark) values ('" + DBName + "', '" + filename + "', '" + remark + "')", true); return(true); } catch (Exception e) { TopFashion.WriteLog.CreateLog("数据库操作", "SQLDbBackup", "error", "备份时出错:" + e.Message); } finally { oSQLServer.DisConnect(); } return(false); }
public static Logicaldisk CreateInstance() { System.Management.ManagementScope mgmtScope = null; if ((statMgmtScope == null)) { mgmtScope = new System.Management.ManagementScope(); mgmtScope.Path.NamespacePath = CreatedWmiNamespace; } else { mgmtScope = statMgmtScope; } System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); return new Logicaldisk(new System.Management.ManagementClass(mgmtScope, mgmtPath, null).CreateInstance()); }
public static LogicaldiskCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { if ((mgmtScope == null)) { if ((statMgmtScope == null)) { mgmtScope = new System.Management.ManagementScope(); mgmtScope.Path.NamespacePath = "root\\cimv2"; } else { mgmtScope = statMgmtScope; } } System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); pathObj.ClassName = "Win32_Logicaldisk"; pathObj.NamespacePath = "root\\cimv2"; System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); if ((enumOptions == null)) { enumOptions = new System.Management.EnumerationOptions(); enumOptions.EnsureLocatable = true; } return new LogicaldiskCollection(clsObject.GetInstances(enumOptions)); }
public static LogicaldiskCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, System.String[] selectedProperties) { if ((mgmtScope == null)) { if ((statMgmtScope == null)) { mgmtScope = new System.Management.ManagementScope(); mgmtScope.Path.NamespacePath = "root\\cimv2"; } else { mgmtScope = statMgmtScope; } } System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new System.Management.SelectQuery("Win32_Logicaldisk", condition, selectedProperties)); System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); enumOptions.EnsureLocatable = true; ObjectSearcher.Options = enumOptions; return new LogicaldiskCollection(ObjectSearcher.Get()); }
private WmiDataProvider GetWmiDataProvider(string @namespace) { if (this.WmiDataProvider != null) return this.WmiDataProvider; var wmiNamespace = String.Format(@"\\{0}\{1}", this.TargetInfo.GetAddress(), @namespace); var wmiNamespacePath = new System.Management.ManagementPath(wmiNamespace); var wmiConnectionOptions = WmiDataProviderFactory.CreateConnectionOptions(this.TargetInfo); var wmiManagementScope = new System.Management.ManagementScope(wmiNamespacePath, wmiConnectionOptions); wmiManagementScope.Connect(); return new WmiDataProvider(wmiManagementScope); }
public static ActionResult GetAndroidUsbDriverVersionWmi( Session session ) { session.Log ( "(DECA) Begin GetAndroidUsbDriverVersionWmi" ); try { System.Management.ManagementClass wmi = new System.Management.ManagementClass ( ); System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery ( string.Format ( CultureInfo.InvariantCulture, WMI_QUERY, REVISION2_GUID ) ); System.Management.ManagementScope oMs = new System.Management.ManagementScope ( ); System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher ( oMs, oQuery ); System.Management.ManagementObjectCollection oResults = oSearcher.Get ( ); if ( oResults.Count > 0 ) { foreach ( var item in oResults ) { string cg = string.Format ( CultureInfo.InvariantCulture, "{0}", item["ClassGuid"] ); if ( !string.IsNullOrEmpty ( cg ) ) { bool foundR1 = string.Compare ( cg, REVISION1_GUID, true ) == 0; bool foundR2 = string.Compare ( cg, REVISION2_GUID, true ) == 0; if ( foundR1 ) { session[ANDROIDUSBDRIVERVERSION] = REVISION1; session[ANDROIDUSBDRIVERSINSTALLED] = "1"; session.Log ( "(DECA) Found Revision 1 version of Android USB Driver" ); return ActionResult.Success; } else if ( foundR2 ) { session[ANDROIDUSBDRIVERVERSION] = REVISION2; session[ANDROIDUSBDRIVERSINSTALLED] = "0"; session.Log ( "(DECA) Found Revision 2 version of Android USB Driver" ); return ActionResult.Success; } else { session.Log ( "(DECA) Did not find a know ClassGuid: {0}", cg ); } } else { session.Log ( "(DECA) ClassGuid was Empty" ); } } } else { session.Log ( "(DECA) No WMI Results were returned." ); } } catch ( Exception ex ) { session.Log ( ex.ToString() ); } session[ANDROIDUSBDRIVERVERSION] = "0"; session[ANDROIDUSBDRIVERSINSTALLED] = "0"; session.Log ( "(DECA) Did not find any version of Android USB Driver" ); return ActionResult.Success; }
private void LoadShares(string Username, string Password, string Computer) { List <Share> shares = new List <Share>(); System.Text.StringBuilder sb = new StringBuilder(); string qry = "select * from win32_share"; System.Management.ManagementObjectSearcher searcher; System.Management.ObjectQuery query = new System.Management.ObjectQuery(qry); if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = Username; oConn.Password = Password; if (!Computer.StartsWith(@"\\")) { Computer = @"\\" + Computer; } if (!Computer.ToLower().EndsWith(@"\root\cimv2")) { Computer = Computer + @"\root\cimv2"; } System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn); searcher = new System.Management.ManagementObjectSearcher(oMs, query); } else { searcher = new System.Management.ManagementObjectSearcher(query); } foreach (System.Management.ManagementObject share in searcher.Get()) { Share s = new Share(); foreach (System.Management.PropertyData p in share.Properties) { switch (p.Name) { case "AccessMask": if (p.Value != null) { s.AccessMask = p.Value.ToString(); } break; case "MaximumAllowed": if (p.Value != null) { s.MaximumAllowed = p.Value.ToString(); } break; case "InstallDate": if (p.Value != null) { s.InstallDate = p.Value.ToString(); } break; case "Description": if (p.Value != null) { s.Description = p.Value.ToString(); } break; case "Caption": if (p.Value != null) { s.Caption = p.Value.ToString(); } break; case "AllowMaximum": if (p.Value != null) { s.AllowMaximum = p.Value.ToString(); } break; case "Name": if (p.Value != null) { s.Name = p.Value.ToString(); } break; case "Path": if (p.Value != null) { s.Path = p.Value.ToString(); } break; case "Status": if (p.Value != null) { s.Status = p.Value.ToString(); } break; case "Type": if (p.Value != null) { s._Type = p.Value.ToString(); } break; default: break; } } shares.Add(s); } this.dataGridView1.DataSource = shares; }
private void LoginButton_Click(object sender, System.EventArgs e) { bool success = false; if (this.MachineNameTextBox.Text == string.Empty) { this.MachineNameTextBox.Text = @"\\localhost\root\cimv2"; } else { if (!this.MachineNameTextBox.Text.StartsWith(@"\\")) this.MachineNameTextBox.Text = @"\\" + this.MachineNameTextBox.Text; } if (!this.MachineNameTextBox.Text.StartsWith(@"\\localhost")) { if (this.UsernameTextBox.Text != string.Empty && this.PasswordTextBox.Text != string.Empty && this.MachineNameTextBox.Text != string.Empty) { try { System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions(); oConn.Username = this.UsernameTextBox.Text; oConn.Password = this.PasswordTextBox.Text; oConn.Impersonation = System.Management.ImpersonationLevel.Impersonate; //oConn.Authority = this.MachineNameTextBox.Text; oConn.Authentication = System.Management.AuthenticationLevel.Connect; System.Management.ManagementScope oMs = new System.Management.ManagementScope(this.MachineNameTextBox.Text, oConn); oMs.Path = new System.Management.ManagementPath( this.MachineNameTextBox.Text ); oMs.Connect(); success = oMs.IsConnected; } catch (Exception exc) { Terminals.Logging.Info("Login Failed", exc); MessageBox.Show(exc.Message); } if (success) { this.Cancelled = false; this.Visible = false; } } } else { this.Cancelled = false; this.Visible = false; } }