can registration be enabled programatically?

Yes sure you can, just update the appropriate option inside your given function..

update_option( 'users_can_register', 1 );

It’s a checkbox option, so the value is 1 = on, 0 = off..

Hope that helps..