Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Turning of the monitors

Turning of the monitors

Scheduled Pinned Locked Moved C#
21 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Daniel Turini

    Usually monitors have a "Power" button... :rolleyes: Yes, even I am blogging now!

    P Offline
    P Offline
    PrebKlok
    wrote on last edited by
    #3

    Well... I have my reasons, so is there a way or not?

    D 1 Reply Last reply
    0
    • P PrebKlok

      Well... I have my reasons, so is there a way or not?

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #4

      Use WMI to call the SetPowerState function on an instance of the CIM_DesktopMonitor class and pass 6 as the new power state. Yes, even I am blogging now!

      P 1 Reply Last reply
      0
      • D Daniel Turini

        Use WMI to call the SetPowerState function on an instance of the CIM_DesktopMonitor class and pass 6 as the new power state. Yes, even I am blogging now!

        P Offline
        P Offline
        PrebKlok
        wrote on last edited by
        #5

        Hmm.. sounds quite easy, but sorry, I'm a newbee at C# so how do I do that?

        H 1 Reply Last reply
        0
        • P PrebKlok

          Hmm.. sounds quite easy, but sorry, I'm a newbee at C# so how do I do that?

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #6

          By reading about the System.Management[^] classes and their examples in the .NET Framework SDK. It's the only way to learn. You can also download the Management Extensions for Visual Studio .NET from the links below, which installs extensions into VS.NET's Server Explorer. You can find the class you want and drag and drop it to your project ot create a typed ManagementObject (supported properties and methods are reflected on the created type), but all this does is provide a wrapper for calling ManagementObject.InvokeMethod, ManagementObject.Get, and ManagementObject.Put.

          • Management (WMI) Extensions for Visual Studio .NET 2002 Server Explorer (RTM)[^]
          • Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer[^]

          Microsoft MVP, Visual C# My Articles

          P 2 Replies Last reply
          0
          • H Heath Stewart

            By reading about the System.Management[^] classes and their examples in the .NET Framework SDK. It's the only way to learn. You can also download the Management Extensions for Visual Studio .NET from the links below, which installs extensions into VS.NET's Server Explorer. You can find the class you want and drag and drop it to your project ot create a typed ManagementObject (supported properties and methods are reflected on the created type), but all this does is provide a wrapper for calling ManagementObject.InvokeMethod, ManagementObject.Get, and ManagementObject.Put.

            • Management (WMI) Extensions for Visual Studio .NET 2002 Server Explorer (RTM)[^]
            • Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer[^]

            Microsoft MVP, Visual C# My Articles

            P Offline
            P Offline
            PrebKlok
            wrote on last edited by
            #7

            Wow, I thought there would be something easy as just function.TurnOffMonitor(x) ... :sigh:

            T H 2 Replies Last reply
            0
            • P PrebKlok

              Wow, I thought there would be something easy as just function.TurnOffMonitor(x) ... :sigh:

              T Offline
              T Offline
              Tom Larsen
              wrote on last edited by
              #8

              Its funny how some think someone else should write their code. Is the monitor power button looking like a more feasible implementation for you? :-) This is easily a case where one can overuse technology. By the time it takes you to figure out how to use the objects in Management you could have just shut off your monitor.

              P 1 Reply Last reply
              0
              • P PrebKlok

                Wow, I thought there would be something easy as just function.TurnOffMonitor(x) ... :sigh:

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #9

                Yeah, right next to DoesEverything.MakeMeCoffee(). :rolleyes: If there was a method or something for every possible feature (which is impossible), what would be the point of having programmers?

                Microsoft MVP, Visual C# My Articles

                N 1 Reply Last reply
                0
                • T Tom Larsen

                  Its funny how some think someone else should write their code. Is the monitor power button looking like a more feasible implementation for you? :-) This is easily a case where one can overuse technology. By the time it takes you to figure out how to use the objects in Management you could have just shut off your monitor.

                  P Offline
                  P Offline
                  PrebKlok
                  wrote on last edited by
                  #10

                  Ahrghhh.... I just wanted a little help for a something that mattered to me, but I guess I'll have to stick to what what my newbe skills could to come up with: private void Form1_Load(object sender, System.EventArgs e) { this.Location = new Point(0,0); this.BackColor = Color.Black; this.Size = new Size(1280*2, 1024); } all through it doesn't turn off the monitors (since my monitors are backlighted), but at least it dims the light. Thank you guys X|

                  N 1 Reply Last reply
                  0
                  • H Heath Stewart

                    Yeah, right next to DoesEverything.MakeMeCoffee(). :rolleyes: If there was a method or something for every possible feature (which is impossible), what would be the point of having programmers?

                    Microsoft MVP, Visual C# My Articles

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #11

                    Heath Stewart wrote: what would be the point of having programmers? Programmers are no longer needed in this world, at least not with the newly released API's containing things like this:

                    IDevelop id = DeveloperFactory.CreateDeveloper();
                    id.WriteCompleteApplicationWithNoErrors();

                    - Nick Parker
                    My Blog | My Articles

                    H 1 Reply Last reply
                    0
                    • P PrebKlok

                      Ahrghhh.... I just wanted a little help for a something that mattered to me, but I guess I'll have to stick to what what my newbe skills could to come up with: private void Form1_Load(object sender, System.EventArgs e) { this.Location = new Point(0,0); this.BackColor = Color.Black; this.Size = new Size(1280*2, 1024); } all through it doesn't turn off the monitors (since my monitors are backlighted), but at least it dims the light. Thank you guys X|

                      N Offline
                      N Offline
                      Nick Parker
                      wrote on last edited by
                      #12

                      PrebKlok wrote: Thank you guys X| What's the bad mood for? Do you not want to learn anything at all? Do you want to be a newbie forever? I suppose, if that's the manner in which you want things handled you should be upset. - Nick Parker
                      My Blog | My Articles

                      1 Reply Last reply
                      0
                      • N Nick Parker

                        Heath Stewart wrote: what would be the point of having programmers? Programmers are no longer needed in this world, at least not with the newly released API's containing things like this:

                        IDevelop id = DeveloperFactory.CreateDeveloper();
                        id.WriteCompleteApplicationWithNoErrors();

                        - Nick Parker
                        My Blog | My Articles

                        H Offline
                        H Offline
                        Heath Stewart
                        wrote on last edited by
                        #13

                        But the factory pattern used in the "new APIs" is from .NET 2.0 Beta. You don't want beta developers, do you? :-D I guess maybe I should just be a park ranger out in Washington now that Redmond has decided us programmers are absolete. :(( :-D

                        Microsoft MVP, Visual C# My Articles

                        N 1 Reply Last reply
                        0
                        • H Heath Stewart

                          But the factory pattern used in the "new APIs" is from .NET 2.0 Beta. You don't want beta developers, do you? :-D I guess maybe I should just be a park ranger out in Washington now that Redmond has decided us programmers are absolete. :(( :-D

                          Microsoft MVP, Visual C# My Articles

                          N Offline
                          N Offline
                          Nick Parker
                          wrote on last edited by
                          #14

                          Heath Stewart wrote: I guess maybe I should just be a park ranger out in Washington now that Redmond has decided us programmers are absolete. Hey, if you did, who could blame you - this[^] view looks awesome. :) - Nick Parker
                          My Blog | My Articles

                          H 1 Reply Last reply
                          0
                          • N Nick Parker

                            Heath Stewart wrote: I guess maybe I should just be a park ranger out in Washington now that Redmond has decided us programmers are absolete. Hey, if you did, who could blame you - this[^] view looks awesome. :) - Nick Parker
                            My Blog | My Articles

                            H Offline
                            H Offline
                            Heath Stewart
                            wrote on last edited by
                            #15

                            Well, when you an Megan come up to visit (BTW - have a thread about my new job in my blog) we can take you there! And since I'm absolete now with that pesky DoesEverything class, we'll probably just have a cabin (so it's close to work) there! :-D

                            Microsoft MVP, Visual C# My Articles

                            1 Reply Last reply
                            0
                            • H Heath Stewart

                              By reading about the System.Management[^] classes and their examples in the .NET Framework SDK. It's the only way to learn. You can also download the Management Extensions for Visual Studio .NET from the links below, which installs extensions into VS.NET's Server Explorer. You can find the class you want and drag and drop it to your project ot create a typed ManagementObject (supported properties and methods are reflected on the created type), but all this does is provide a wrapper for calling ManagementObject.InvokeMethod, ManagementObject.Get, and ManagementObject.Put.

                              • Management (WMI) Extensions for Visual Studio .NET 2002 Server Explorer (RTM)[^]
                              • Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer[^]

                              Microsoft MVP, Visual C# My Articles

                              P Offline
                              P Offline
                              PrebKlok
                              wrote on last edited by
                              #16

                              Ok, would this be the way to go? object [] arg = {6}; ManagementClass mc = new ManagementClass("Win32_DesktopMonitor"); mc.InvokeMethod("SetPowerState", arg); problem is that I get the an exception: An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll Additional information: This method is not implemented in any class

                              H 1 Reply Last reply
                              0
                              • P PrebKlok

                                Ok, would this be the way to go? object [] arg = {6}; ManagementClass mc = new ManagementClass("Win32_DesktopMonitor"); mc.InvokeMethod("SetPowerState", arg); problem is that I get the an exception: An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll Additional information: This method is not implemented in any class

                                H Offline
                                H Offline
                                Heath Stewart
                                wrote on last edited by
                                #17

                                If you followed my directions (downloaded the WMI extensions for VS.NET) and generated a typed class for the Win32_DesktopMonitor CIMv2 class, you might see immediately what was wrong: SetPowerState takes two parameters: a UInt16 and a DateTime. Change the first line to object[] arg = {6, DateTime.Now}; and it should work.

                                Microsoft MVP, Visual C# My Articles

                                P 1 Reply Last reply
                                0
                                • H Heath Stewart

                                  If you followed my directions (downloaded the WMI extensions for VS.NET) and generated a typed class for the Win32_DesktopMonitor CIMv2 class, you might see immediately what was wrong: SetPowerState takes two parameters: a UInt16 and a DateTime. Change the first line to object[] arg = {6, DateTime.Now}; and it should work.

                                  Microsoft MVP, Visual C# My Articles

                                  P Offline
                                  P Offline
                                  PrebKlok
                                  wrote on last edited by
                                  #18

                                  Hmm... changing the line now gives this execption: An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll Additional information: Type mismatch I'm not sure if I understood your direction 100%. After having installed the WMI extensions, I opened the Server Explore and browsed to Servers|MyComputerName|Management Clas|Desktop Settings and then I right clicked and chose "Generate Managed Class"

                                  H 1 Reply Last reply
                                  0
                                  • P PrebKlok

                                    Hmm... changing the line now gives this execption: An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll Additional information: Type mismatch I'm not sure if I understood your direction 100%. After having installed the WMI extensions, I opened the Server Explore and browsed to Servers|MyComputerName|Management Clas|Desktop Settings and then I right clicked and chose "Generate Managed Class"

                                    H Offline
                                    H Offline
                                    Heath Stewart
                                    wrote on last edited by
                                    #19

                                    That's not the right class. You have to right-click on "Management Classes" and add a new class: root\CIMv2\Win32_DesktopMonitor. Generate a new class from that. Try object[] arg = new object[] {(ushort)6, DateTime.Now};. It really shouldn't matter since non-decimal numeric types are implicitly convertible, but it's worth a try. This could present a problem since the method is discovered by the types of parameters, and since just 6 would actually be an int (System.Int32), that could be the source of the problem.

                                    Microsoft MVP, Visual C# My Articles

                                    P 1 Reply Last reply
                                    0
                                    • H Heath Stewart

                                      That's not the right class. You have to right-click on "Management Classes" and add a new class: root\CIMv2\Win32_DesktopMonitor. Generate a new class from that. Try object[] arg = new object[] {(ushort)6, DateTime.Now};. It really shouldn't matter since non-decimal numeric types are implicitly convertible, but it's worth a try. This could present a problem since the method is discovered by the types of parameters, and since just 6 would actually be an int (System.Int32), that could be the source of the problem.

                                      Microsoft MVP, Visual C# My Articles

                                      P Offline
                                      P Offline
                                      PrebKlok
                                      wrote on last edited by
                                      #20

                                      I can't find any Win32_xxxxx in root\CIMv2\ Here is a screenshot of what is see: www.klokmose.dk/images/screen1.jpg[^] Anyway the (ushort)6 didn't help anything

                                      H 1 Reply Last reply
                                      0
                                      • P PrebKlok

                                        I can't find any Win32_xxxxx in root\CIMv2\ Here is a screenshot of what is see: www.klokmose.dk/images/screen1.jpg[^] Anyway the (ushort)6 didn't help anything

                                        H Offline
                                        H Offline
                                        Heath Stewart
                                        wrote on last edited by
                                        #21

                                        Since the dialog is showing the friendly names, the logical conclusion would be to find something that resembles "Win32_DesktopMonitor", like "Monitors". Add that and generate a class for your project.

                                        Microsoft MVP, Visual C# My Articles

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups