title: Disconnect and Reconnect Displays Programmatically
body: <p><strong>Question:</strong> What is the best way to programmatically disconnect and reconnect displays programmatically? </p>
  
  <p><strong>The Goal:</strong> Kill the video output (black screen with no backlight) on a display and later turn it back on. Imagine unplugging the video cord from the monitor, then plugging it back in.</p>
  
  <p><strong>My Attempt:</strong></p>
  
  <pre><code>// Get the monitor to disable
  uint iDevNum = 0;
  DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
  displayDevice.cb = Marshal.SizeOf(displayDevice);
  EnumDisplayDevices(null, iDevNum, ref displayDevice, 0))
  
  DEVMODE devMode = new DEVMODE();
  EnumDisplaySettings(displayDevice.DeviceName, 0, ref devMode);
  
  //
  // Do something here to disable this display device!
  //
  
  // Save the display settings
  ChangeDisplaySettingsEx(displayDevice.DeviceName, ref devMode, 
      IntPtr.Zero, ChangeDisplaySettingsFlags.CDS_NONE, IntPtr.Zero);
  </code></pre>
  
  <p>I can interact with each display, but I can't figure out how to disconnect one.</p>
  
  <p>It is similar to "Disconnect this display" in the Screen Resolution properties in Windows 7:</p>
  
  <p><img src="https://i.stack.imgur.com/tfAjh.png" alt="Windows 7 Screen Resolution Properties"></p>
  
  <p><strong>Notes:</strong> </p>
  
  <ul>
  <li>Turning off video output on all displays won't work because I need the other monitors to stay on.</li>
  <li>The desktop area on the "dead" display does NOT need to be usable when it is off. Also, it is fine if windows move around.</li>
  </ul>
  
  <p><strong>References:</strong></p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/233411/how-do-i-enable-a-second-monitor-in-c" title="Enabling a Second Monitor">SO: Enabling a Second Monitor</a></li>
  <li><a href="http://www.codeproject.com/Articles/12794/Complete-Guide-on-How-To-Turn-A-Monitor-On-Off-Sta" rel="nofollow noreferrer" title="How to Turn a Monitor Off">How to Turn Off a Monitor</a></li>
  </ol>