Programmatically change logo
That setting is part of the theme settings variable; each setting is put in an array and that array is serialised as the value of the main theme settings variable.

You can set this value programmatically like so:

$theme_name = 'garland';  
$var_name = 'theme_' . $theme_name . '_settings';

$settings = variable_get($var_name, array());

$settings['logo_path'] = $new_path;

variable_set($var_name, $settings);