How do you set the window resolution for a game?

Have you tried playing with console commands and then calling a console command from a method?