I wrote the following code to disable the a guest os's virtual monitor programatically:
def disableSecondMonitor():
import win32api
import win32con as C
name = win32api.EnumDisplayDevices(None, 1).DeviceName
devmode = win32api.EnumDisplaySettingsEx(name, 0)
devmode.Clear()
devmode.Fields = C.DM_PELSWIDTH | C.DM_PELSHEIGHT | C.DM_BITSPERPEL | \
C.DM_POSITION | C.DM_DISPLAYFREQUENCY | C.DM_DISPLAYFLAGS
win32api.ChangeDisplaySettingsEx(name, devmode, C.CDS_UPDATEREGISTRY)
win32api.ChangeDisplaySettingsEx(name, devmode, C.CDS_UPDATEREGISTRY)
The code is adapted from this article which says to make the API call twice with a zero-ed out devmode
.
The strange thing is, the code works once in a while, but most often it causes the VM to restart. Any ideas?