{"id":1938,"date":"2012-05-03T17:52:51","date_gmt":"2012-05-03T17:52:51","guid":{"rendered":"http:\/\/craftydba.com\/?p=1938"},"modified":"2024-02-17T14:25:26","modified_gmt":"2024-02-17T14:25:26","slug":"runas-ssms-vbscript","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=1938","title":{"rendered":"RunAs SSMS VB Script"},"content":{"rendered":"<p>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.<\/p>\n<p>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.  <\/p>\n<p><span style=\"color: #FF0000; font-size:medium;\">How does one easily switch from one windows account to another?<\/span><\/p>\n<p>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.<\/p>\n<p><span style=\"color: #FF0000; font-size:medium;\">Do not fret!<\/span><\/p>\n<p>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 (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms174173.aspx\">SSMS<\/a>) application is executed under those credentials.  <\/p>\n<p>A closer examination of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/d1wf56tt(v=vs.84).aspx\">VB Script<\/a> reveals the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/3yfdhzk5(v=vs.84).aspx\">INPUTBOX<\/a>() statements is used to prompt the user for a domain account and password.  A native Windows <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aew9yb99(v=VS.85).aspx\">shell<\/a> object is generated to execute the DOS <a href=\"http:\/\/www.microsoft.com\/resources\/documentation\/windows\/xp\/all\/proddocs\/en-us\/runas.mspx?mfr=true\">RUNAS<\/a> command under the supplied domain account.  The problem is that the shell requires key strokes to enter the password.  This is where the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/8c6yea83(v=VS.85).aspx\">SENDKEYS<\/a>() saves the day.  The &#8220;~&#8221; indicates the enter key has been pressed.<\/p>\n<p>The first screen shot shows the user being prompted for the account.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-account.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-account.jpg\" alt=\"\" title=\"runas-ssms-prompt-account\" width=\"374\" height=\"168\" class=\"aligncenter size-full wp-image-1951\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-account.jpg 374w, https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-account-300x134.jpg 300w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/a><\/p>\n<p>The second screen shot shows the user being prompted for the password.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-password.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-password.jpg\" alt=\"\" title=\"runas-ssms-prompt-password\" width=\"375\" height=\"166\" class=\"aligncenter size-full wp-image-1956\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-password.jpg 375w, https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-prompt-password-300x132.jpg 300w\" sizes=\"auto, (max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<p>The third screen shot shows SSMS running under the credentials your supplied.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-admin-user.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-admin-user.jpg\" alt=\"\" title=\"runas-ssms-admin-user\" width=\"427\" height=\"322\" class=\"aligncenter size-full wp-image-1950\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-admin-user.jpg 427w, https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms-admin-user-300x226.jpg 300w\" sizes=\"auto, (max-width: 427px) 100vw, 427px\" \/><\/a><\/p>\n<p>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 <a href='https:\/\/craftydba.com\/wp-content\/uploads\/2012\/05\/runas-ssms.vbs_.txt'>RUNAS-SSMS.VBS<\/a>  a try when you want to switch between DOMAIN accounts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[422,421,12,419,15,418,420,13],"class_list":["post-1938","post","type-post","status-publish","format-standard","hentry","category-other","tag-different-credentials","tag-execute-ssms","tag-free-code","tag-inputbox","tag-john-f-miner-iii","tag-runas","tag-sendkeys","tag-vb-script-2"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/1938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1938"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/1938\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}