No need for all of that. You could just use this:
That will set the graphics mode to the highest resolution and color depth the user's computer can support.
c=CountGFXModes3d() Graphics3d GFXModeWidth(c),GFXModeHeight(c),GFXModeDepth(c),1
That will set the graphics mode to the highest resolution and color depth the user's computer can support.