A seperation of power between a day-to-day user account and a special occasion adminstrator account can be beneficial for a DBA. By usig a less privledge account for daily activities can avoid costly human mistakes. A mistake will be denied due to not having the correct privledges.
It is standard to use Microsoft Windows Domain Accounts for daily adhoc queries. A Standard SQL Account is usually used by custom applications to connect and perform work in the database.
How does one easily switch from one windows account to another?
A less ideal solution is to logout of the user account and login with the administrator account. This can easily waste a couple of minutes each time this process is done.
Do not fret!
I will be supplying you today with a VB Script that asks for a domain account and password. After acquiring this information, the SQL Server Management Studio (SSMS) application is executed under those credentials.
A closer examination of the VB Script reveals the INPUTBOX() statements is used to prompt the user for a domain account and password. A native Windows shell object is generated to execute the DOS RUNAS command under the supplied domain account. The problem is that the shell requires key strokes to enter the password. This is where the SENDKEYS() saves the day. The “~” indicates the enter key has been pressed.
The first screen shot shows the user being prompted for the account.
The second screen shot shows the user being prompted for the password.
The third screen shot shows SSMS running under the credentials your supplied.
A nice thing about the script is that the targer program can be any valid Windows program. This is a tool that you can modify to your own needs. In the future, give the RUNAS-SSMS.VBS a try when you want to switch between DOMAIN accounts.