Пример #1
0
        //public static (int major, int minor, int build) tpGetOSVersion()
        public static void tpGetOSVersion(out int major, out int minor, out int build)
        {
            //var result = (major: 0, minor: 0, build: 0);
            major = 0;
            minor = 0;
            build = 0;

            System.Management.ManagementClass mc =
                new System.Management.ManagementClass("Win32_OperatingSystem");
            System.Management.ManagementObjectCollection moc = mc.GetInstances();

            foreach (System.Management.ManagementObject mo in moc)
            {
                string   ver        = mo["Version"].ToString();
                string[] majorminor = ver.Split(new char[] { '.' }, StringSplitOptions.None);

                major = Convert.ToInt32(majorminor[0]);
                minor = Convert.ToInt32(majorminor[1]);
                build = Convert.ToInt32(mo["BuildNumber"]);

                break;                  // 1回ループで終了(でいいよね)
            }
            moc.Dispose();
            mc.Dispose();

            //return result;
        }
Пример #2
0
        //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);
        }
Пример #3
0
        //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)
            {
                MessageBox.Show("Sorry, Your System does not support this brightness control...");
            }

            return(BrightnessLevels);
        }
Пример #4
0
        static byte[] QueryAvailableBrightnessLevels()
        {
            byte[] BrightnessLevels = new byte[0];
            System.Management.ManagementScope          ManScope = new System.Management.ManagementScope("ROOT\\WMI");
            System.Management.SelectQuery              ManQuery = new System.Management.SelectQuery("WmiMonitorBrightness");
            System.Management.ManagementObjectSearcher ManObjS  = new System.Management.ManagementObjectSearcher(ManScope, ManQuery);

            try
            {
                System.Management.ManagementObjectCollection ManObjC = ManObjS.Get();
                foreach (System.Management.ManagementObject ManObject in ManObjC)
                {
                    BrightnessLevels = (byte[])ManObject.GetPropertyValue("Level");
                    break;
                }

                ManObjC.Dispose();
                ManObjS.Dispose();
            }
            catch (Exception VideoException)
            {
                MessageBox.Show("Unable to get available brightness levels. The video card may not support this feature or the driver is not installed. Error: " + VideoException.Message, "BControl", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(BrightnessLevels);
        }
Пример #5
0
        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);
                    //properties = o.Properties;
                    //o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise!
                    break; //only work on the first object
                }
            }
            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();
                }
            }
        }
Пример #6
0
        static void injectBrightnessWithValue(byte brightness)
        {
            System.Management.ManagementScope            ManScope = new System.Management.ManagementScope("ROOT\\WMI");
            System.Management.SelectQuery                ManQuery = new System.Management.SelectQuery("WmiMonitorBrightnessMethods");
            System.Management.ManagementObjectSearcher   ManObjS  = new System.Management.ManagementObjectSearcher(ManScope, ManQuery);
            System.Management.ManagementObjectCollection ManObjC  = ManObjS.Get();

            foreach (System.Management.ManagementObject ManObject in ManObjC)
            {
                ManObject.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, brightness });
                break;
            }

            ManObjC.Dispose();
            ManObjS.Dispose();
        }
Пример #7
0
        // Set screen brightness
        static void SetBrightness(byte targetBrightness)
        {
            System.Management.ManagementScope          s   = new System.Management.ManagementScope("root\\WMI");               // Define scope (namespace)
            System.Management.SelectQuery              q   = new System.Management.SelectQuery("WmiMonitorBrightnessMethods"); // Define query
            System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q);             // Output current screen brightness

            System.Management.ManagementObjectCollection moc = mos.Get();

            // Store result is reversed order - apparently won't work otherwise
            foreach (System.Management.ManagementObject o in moc)
            {
                o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness });
                break; // Only work on the first object
            }

            moc.Dispose();
            mos.Dispose();
        }
Пример #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.UseWaitCursor             = true;
            buttonSave.Enabled             = false;
            checkedListBoxPrinters.Enabled = false;
            listBoxPrinters.Enabled        = false;
            labelWait.Left    = splitContainer1.Left + (splitContainer1.Width - labelWait.Width) / 2;
            labelWait.Top     = splitContainer1.Top + (splitContainer1.Panel1.Height - labelWait.Height) / 2;
            labelWait.Visible = true;
            checkedListBoxPrinters.Refresh();
            listBoxPrinters.Refresh();
            labelWait.Refresh();
            this.Refresh();

            PrintServer ps = new PrintServer();

            foreach (object o in checkedListBoxPrinters.Items)
            {
                string proc = "";
                int    i    = checkedListBoxPrinters.Items.IndexOf(o);
                if (checkedListBoxPrinters.GetItemChecked(i))
                {
                    proc = "mariaprint";
                }
                else
                {
                    proc = "winprint";
                }

                System.Management.ManagementObjectSearcher   mos = new System.Management.ManagementObjectSearcher("Select * from Win32_Printer where Name='" + o.ToString() + "'");
                System.Management.ManagementObjectCollection moc = mos.Get();
                foreach (System.Management.ManagementObject printer in moc)
                {
                    printer["PrintProcessor"] = proc;
                    printer.Put();
                    printer.Dispose();
                }
                moc.Dispose();
                mos.Dispose();
            }

            this.UseWaitCursor = false;
            this.Close();
        }
Пример #9
0
        static int FetchCurrentBrightness()
        {
            byte CurrentBrightness = 0;

            System.Management.ManagementScope            ManScope = new System.Management.ManagementScope("ROOT\\WMI");
            System.Management.SelectQuery                ManQuery = new System.Management.SelectQuery("WmiMonitorBrightness");
            System.Management.ManagementObjectSearcher   ManObjS  = new System.Management.ManagementObjectSearcher(ManScope, ManQuery);
            System.Management.ManagementObjectCollection ManObjC  = ManObjS.Get();

            foreach (System.Management.ManagementObject ManObject in ManObjC)
            {
                CurrentBrightness = (byte)ManObject.GetPropertyValue("CurrentBrightness");
                break;
            }

            ManObjC.Dispose();
            ManObjS.Dispose();

            return((int)CurrentBrightness);
        }
Пример #10
0
        private bool setBrightness(int brightness)
        {
            byte brightnessInBytes;

            if (brightness >= 0 && brightness <= 100)
            {
                brightnessInBytes = (byte)(brightness);
            }
            else
            {
                return(false);
            }

            try
            {
                /* DANGER ZONE CODE - Only about 80% sure what this does */

                System.Management.ManagementScope            scope = new System.Management.ManagementScope("root\\WMI");
                System.Management.SelectQuery                query = new System.Management.SelectQuery("WmiMonitorBrightnessMethods");
                System.Management.ManagementObjectSearcher   mos   = new System.Management.ManagementObjectSearcher(scope, query);
                System.Management.ManagementObjectCollection moc   = mos.Get();

                foreach (System.Management.ManagementObject o in moc) //Don't ask questions you don't want to know the answer to
                {
                    o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, brightnessInBytes });
                    break; //Searously
                }

                moc.Dispose();
                mos.Dispose();

                /* END OF DANGER ZONE CODE */
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
                return(false);
            }
            return(true);
        }
Пример #11
0
        private void SetSlideBarStatus(int a, int b)
        {
            if (a != 1)
            {
                return;
            }



            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();

                while (true)
                {
                    mok = mox.Get();

                    foreach (System.Management.ManagementObject o in mok)
                    {
                        byte[] curBytes = o.Properties["IOBytes"].Value as byte[];
                        if (b == 32 || b == 33)
                        {
                            curBytes[84] = (byte)(b % 2);
                        }
                        if (b == 0 || b == 1)
                        {
                            curBytes[83] = (byte)(b % 2);
                        }
                        //curBytes[85] = 1;
                        //curBytes[66] = 4;
                        o.SetPropertyValue("IOBytes", curBytes);
                        //properties = o.Properties;
                        //o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise!
                        break; //only work on the first object
                    }

                    //Console.WriteLine(properties["IOBytes"].Value);
                    PropertyData ioBytes = properties["IOBytes"];
                    byte[]       bytes   = ioBytes.Value as byte[];
                    //bytes[83] = 100;
                    //lastBytes = bytes;
                    //((byte[])ioBytes.Value)[83] = 4;
                    //((byte[])ioBytes.Value)[84] = 100;
                    //int place = -1;
                    //if (!isTheSame(bytes, out place))
                    //{
                    //    Console.WriteLine("PLACE: " + place);
                    //    Console.WriteLine(BitConverter.ToString(bytes));
                    //}
                    //if (bytes[83] < 3) 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();
                }
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Console.LargestWindowWidth - 5, Console.LargestWindowHeight - 1);
            PropertyDataCollection properties = null;

            System.Management.ManagementObjectSearcher   mox = null;
            System.Management.ManagementObjectCollection mok = null;
            int repeatTimes = 0;

            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();
                while (true)
                {
                    using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = mox.Get().GetEnumerator())
                    {
                        if (enumerator.MoveNext())
                        {
                            ManagementObject managementObject = (ManagementObject)enumerator.Current;

                            ConsoleKeyInfo ckey = Console.ReadKey();
                            if (ckey.Key == ConsoleKey.C)
                            {
                                break;
                            }
                            if (ckey.Key == ConsoleKey.F)
                            {
                                managementObject.SetPropertyValue("Active", false);
                            }
                            else
                            {
                                if (ckey.Key == ConsoleKey.T)
                                {
                                    managementObject.SetPropertyValue("Active", true);
                                }
                                else
                                {
                                    Console.WriteLine((bool)managementObject["Active"]);
                                }
                            }
                            managementObject.Put();
                        }
                    }
                }

                while (true)
                {
                    System.Threading.Thread.Sleep(200);
                    mok = mox.Get();


                    foreach (System.Management.ManagementObject o in mok)
                    {
                        properties = o.Properties;
                        //o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise!
                        break; //only work on the first object
                    }

                    //Console.WriteLine(properties["IOBytes"].Value);
                    PropertyData ioBytes = properties["IOBytes"];
                    byte[]       bytes   = ioBytes.Value as byte[];
                    //bytes[83] = 100;
                    //lastBytes = bytes;
                    //((byte[])ioBytes.Value)[83] = 4;
                    //((byte[])ioBytes.Value)[84] = 100;
                    int place = -1;
                    if (!isTheSame(bytes, out place))
                    {
                        if (++repeatTimes >= 10)
                        {
                            repeatTimes = 0;
                            Console.Clear();
                        }
                        string message =
                            "PLACE: " + place + "\r\n"
                            + BitConverter.ToString(bytes);

                        Console.WriteLine(message);
                    }
                }
            }
            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();
                }
            }
        }