Open DirectX Diagnostic Tool by clicking the Start button or windows key and pressing R at the same time typing dxdiag in the search box, and then pressing Enter.Click the System tab, and then, under System Information, check the DirectX version number.
Type regedit in the serch box first press windows key and R at the same time then click on the folders as listed you can check "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX" registry for DirectX version
The registry only includes the correct number for versions up to DX 9.0c (4.09.* is DX9, 4.08* is DX8 etc). There doesn't appear to be any nice way to retrieve this number without hard coding assumptions except via dxdiag. I did a quick Google-fu and the only suggestions I found were using dxdiag's COM interface, parsing DX DLL version numbers or reading an XML dump from dxdiag.
For the sake of simplicity you can just look at the OS version and infer the DX version from that (if it's XP or earlier, then you can use the registry), but you'll need to keep your application updated when new Windows versions are released.