As I understand (let me know if wrong..)
1) you have many programs starting same way
2) Some will pop-up log on window
3) When pop-up, need different log on details...
4) you are scripting with jScript or JavaScrip.
5) you need generic code to handle log on window/dialog
On my perspective it's not a good practice to handle those with OnUnexpectedWindow event, because you are expecting those log-on.
My suggestion is write a common function in (jScript ) and call it when ever appears log on dialogue. If JavaScript you can have a class which would inherit a log on function
I assume you know which program you suppose to run. and you know program need log on or not. If so you have to just call common log on function with matching parameters.