Need to run some queries or profiler under a different domain user?

This is an awesome trick I learned from Greg Howe, (all credit to him). While having to connect to another network and have the need to run queries on a db on that network, I usually had to remote in to that machine and run the queries. Well that is no longer the case. Create a batch file called “Launch SSMS.bat” and another one call “Launch Profiler.bat”. Inside those paste the following:

Launch SSMS.bat

C:\Windows\System32\runas.exe /netonly /user:[domain]\[username] “C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”

Launch Profiler.bat

C:\Windows\System32\runas.exe /netonly /user:[domain]\[username] “C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\Profiler.exe”

Now when I am connected to the client’s domain and double click the “Launch SSMS.bat” file I get the following:

I enter my password and it launches SSMS:

Enter your servername in and don’t worry that your user name shows your currently logged in username, it will run SSMS as the credentials in the batch file. Hit connect and then voila, you can now run your queries locally.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s