Does it work manually? You could try to write a batch file, and call that.
You could even write a batch file on the fly