{"id":1413,"date":"2016-06-28T11:56:54","date_gmt":"2016-06-28T09:56:54","guid":{"rendered":"http:\/\/vady.kiev.ua\/tweets\/?p=1413"},"modified":"2016-06-28T11:58:18","modified_gmt":"2016-06-28T09:58:18","slug":"how-to-switch-off-display-with-powershell","status":"publish","type":"post","link":"https:\/\/vady.kiev.ua\/tweets\/1413","title":{"rendered":"How to switch off display with PowerShell"},"content":{"rendered":"<p><em>Define new static type Utilities.Display<\/em><\/p>\n<pre># Turn display off by calling WindowsAPI.\r\n \r\n# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF)\r\n# HWND_BROADCAST  0xffff\r\n# WM_SYSCOMMAND   0x0112\r\n# SC_MONITORPOWER 0xf170\r\n# POWER_OFF       0x0002\r\n \r\nAdd-Type -TypeDefinition '\r\nusing System;\r\nusing System.Runtime.InteropServices;\r\n \r\nnamespace Utilities {\r\n   public static class Display\r\n   {\r\n      [DllImport(\"user32.dll\", CharSet = CharSet.Auto)]\r\n      private static extern IntPtr SendMessage(\r\n         IntPtr hWnd,\r\n         UInt32 Msg,\r\n         IntPtr wParam,\r\n         IntPtr lParam\r\n      );\r\n \r\n      public static void PowerOff ()\r\n      {\r\n         SendMessage(\r\n            (IntPtr)0xffff, \/\/ HWND_BROADCAST\r\n            0x0112,         \/\/ WM_SYSCOMMAND\r\n            (IntPtr)0xf170, \/\/ SC_MONITORPOWER\r\n            (IntPtr)0x0002  \/\/ POWER_OFF\r\n         );\r\n      }\r\n   }\r\n}\r\n'<\/pre>\n<p>Run<br \/>\n<code>[Utilities.Display]::PowerOff()<\/code><\/p>\n<p>or via func<\/p>\n<p><code>function Switch-DisplayOff<br \/>\n{<br \/>\n   [Utilities.Display]::PowerOff()<br \/>\n}<\/code><\/p>\n<p><small>\u00a92013 <a href=\"http:\/\/www.powershellmagazine.com\/2013\/07\/18\/pstip-how-to-switch-off-display-with-powershell\/\" target=\"_blank\">Jakub Jare\u0161<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Define new static type Utilities.Display # Turn display off by calling WindowsAPI. # SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF) # HWND_BROADCAST 0xffff # WM_SYSCOMMAND 0x0112 # SC_MONITORPOWER 0xf170 # POWER_OFF 0x0002 Add-Type -TypeDefinition &#8216; using System; using System.Runtime.InteropServices; namespace Utilities { public static class Display { [DllImport(&#8220;user32.dll&#8221;, CharSet = CharSet.Auto)] private static extern IntPtr SendMessage( IntPtr hWnd, UInt32 &hellip; <a href=\"https:\/\/vady.kiev.ua\/tweets\/1413\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to switch off display with PowerShell<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[75,404,134,403,55],"class_list":["post-1413","post","type-post","status-publish","format-standard","hentry","category-talks","tag-code","tag-monitor","tag-powershell","tag-screen","tag-windows"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7bIIX-mN","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/posts\/1413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/comments?post=1413"}],"version-history":[{"count":2,"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/posts\/1413\/revisions"}],"predecessor-version":[{"id":1415,"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/posts\/1413\/revisions\/1415"}],"wp:attachment":[{"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/media?parent=1413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/categories?post=1413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vady.kiev.ua\/tweets\/wp-json\/wp\/v2\/tags?post=1413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}