I'd probably try using AOMEI Backupper - it has a free version which should include the Clone tools:
Best Free Backup Software for Windows 10, Windows 8.1/8, Windows 7, Vista, XP[
^] (I use the "Professional" version, which means I paid for it and get a few extra features - worth paying for tthough as it's brilliant software).
The clone tools allow you to make image files from SD cards, which means you can restore them, and it has a command line interface:
Backup by using command line with AOMEI Backupper[
^] - which may support cloning but does support backup to image, which should work from an SD card (it works from my USB flash)
And command line interfaces mean your code can control it via the Process class.