you can’t, especialy on windows it’s impossible to be certain that a device you are opening is the device you closed remembered some time ago.

i save both the device index (int the device table that juce gives) and the device name as a String, and try to match both, if both don’t match try to match the name, if the name doesn’t match try to match the index, if that fails, give an error.