Programmatically Change Monitor Display on Windows 7 or 8 using VB.Net

In order to change monitors, it is useful to know what process to be launched to switch displays, the path where the process to be called, and the parameters to pass to the command.

First, we need to know what will be the process to be called. “DisplaySwitch.exe” is the application that runs as a process to change between monitors. It can be launched through several methods and usually can be found on the system folder.

Next, we will get the parameters for our command:

  1. PC Screen Only – "/internal"
  2. Duplicate – "/clone"
  3. Extend – "/extended"
  4. Second Screen Only – "/external"


These four are selections for our displays. Each has its own parameter as a command for the process. For example, if we send a command to the system "DisplaySwitch.exe /clone" with spaces in between, the display will duplicate itself to all monitors.

Now we know how to change the display of our monitor. Next is to run the command programmatically.

The command shell on windows can also be used in vb.net by using "Shell" with 3 parameters but the last 2 are optional. This time, we will just use 1 parameter with data type string as the path name and as the name of the program to be executed. The syntax is:

Shell(PathName)

This time, we want to duplicate the display of our primary monitor so we need to use the complete command with a parameter. The complete code is:

Shell("DisplaySwitch.exe /clone")

Don’t forget that there’s a space between the program name and the parameter.

If we try to build and run our program in vb.net having this code, our screen will be displayed on both monitors.

0 comments:

Post a Comment