Mark,
See attached file. It was acquired from NI by someone at my company. I added a couple of the inputs to increase the flexibility.
A tip to using it. I put a variable '1stBoot' in my program's ini file and if its true this code will run. If DSN gets setup with no errors, i change the value of '1stBoot' to false.
Have fun,
Jared