There are many times that you want to run an application as a different user. You might want to test out security as a different restricted user, or connect to a service on another domain. This command should be able to help you out. I wish I knew about it long ago, it would have saved me so much time.
Probably the simplest way to run an application as another user it to use the shift-right-click functionality in windows. You do this by pressing the shift key and right-clicking on the application icon. You then should get hte option to "Run as a different User". You then are prompted for credentials. Once authenticated the application will start running as that user.
This works great, but there are some issues. The main issue that I always ran into was that the application is now running as the user you select. You probably are thinking Duh! But that means shortcuts to local resources like the Desktop or My Documents may not be accessible. At the very least they will point to the resources for the account you are running as.
So what other options are there? There is a nifty command called runas.exe There are a number of switches, but the ones I want to mention are /user and /netonly. The /user switch defines which account you want to use. You can enter it in the form of user@domain or domain\user.
The second switch is /netonly. This help says this switch will only use the specified credentials for remote access only. So when accessing services on the workstation you are logged into, or access local resources like your My Documents, you will be able to access them as you would with out the runas command. However, if you try to connect to a remote resource on another machine the specified user account is now used. This is amazing, I wish I would have known of this switch years ago! This will be such a time saver as I use SQL Server Management Studio and frequently open and save scripts to local drives.
Now how do we use this? The obvious way is to open a command prompt and type out the command in the following format:
runas.exe /netonly /user:Domain\user application
But that isn't always the best way. A simpler way might be to create a shortcut. This way you can simply just click the shortcut to start the application as the other user. This is ideal if you perform this action a lot, saving you time by not having to type in the command.
To create the shortcut, just right right-click on your desktop and select new shortcut. In the text box for the location enter the command above. Next enter the name of the shortcut that you would like. I like to use something in the form of 'SSMS as domain\user'. Click finish and you are done. Now if you want to be fancy then right-click on your new shortcut and select properties. You can now modify any remaining properties like the Icon. If you click "Change Icon..." and point to your application, it will probably have an embedded icon that you can use. You can also right-click and pin to the start menu or taskbar, whichever you prefer.
Now that you have a shortcut you can run the application. A command window will open prompting you for your password. Enter it in and press Enter.
If successful, you will see a message that it is attempting to start the application.
Once the application starts you will be able to access the remote resources using the specified user. Hope this helps someone out!