Programmatically change logo I tried two versions:
1.

$form_state = array();
form_load_include($form_state, 'inc', 'system', 'system.admin');
$form_state['values']['var'] = 'theme_settings';
$form_state['values']['logo_upload'] = file_save_upload('/path/to/logo.jpg');

drupal_form_submit('system_theme_settings_submit', $form_state);


2.

 variable_set('logo_path', '/path/to/my/uploaded/logo.jpg'); 


but none of them worked.
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);