The code is correct. I'm more interested in knowing what you did to get it to fail the way you describe.
An application, when launched, is launched as the user that launched it. It inherits the users security token. AT NO TIME is the application running as another user or system account and then switches to the current user, unless explicitly coded to do so! And even then, it will launch as the user first, then switch the another account.
If this application needs the users admin privileges, then you should be creating a manfiest for the app and changing the
requestedExecutionLevel
as spelled out in
these[
^].
There's no need for a username and password box for that.