{"id":70503,"date":"2005-02-04T19:05:00","date_gmt":"2005-02-04T19:05:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/02\/04\/how-can-i-mask-passwords-using-an-inputbox\/"},"modified":"2005-02-04T19:05:00","modified_gmt":"2005-02-04T19:05:00","slug":"how-can-i-mask-passwords-using-an-inputbox","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-mask-passwords-using-an-inputbox\/","title":{"rendered":"How Can I Mask Passwords Using an InputBox?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/> <\/p>\n<p>Hey, Scripting Guy! How can I mask passwords using an InputBox?<\/p>\n<p>&#8212; PG<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\" \/><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\" \/><\/a> <\/p>\n<p>Hey, PG. If you\u2019re hoping to mask passwords using a function or method built into WSH or VBScript we\u2019re afraid you\u2019ll be disappointed; neither technology supports password masking. That doesn\u2019t mean you can\u2019t do it, it just means we\u2019ll have to look beyond the core scripting technologies.<\/p>\n<p>If you\u2019re running Windows XP or Windows Server 2003, you can use <b>ScriptPW<\/b> (a COM object found only in those two versions of Windows) to mask passwords from the command line. Here\u2019s a sample script that creates an instance of the ScriptPW.Password object and then uses the StdOut Write method to request that the user enter a password:<\/p>\n<pre class=\"codeSample\">Set objPassword = CreateObject(\"ScriptPW.Password\") \nWScript.StdOut.Write \"Please enter your password:\" \n\nstrPassword = objPassword.GetPassword() \nWscript.Echo\nWscript.Echo \"Your password is: \" &amp; strPassword\n<\/pre>\n<p>When you run this script, the message <b>Please enter your password:<\/b> appears on the screen. At that point, the script will pause and wait for you to type in a password; you simply type the password and press ENTER. This line of code will then grab the password and store it in the variable strPassword:<\/p>\n<pre class=\"codeSample\">strPassword = objPassword.GetPassword()\n<\/pre>\n<p>For this simple script, we just echo back the password typed in to prove that the keystrokes really <i>were<\/i> captured. We do this because with ScriptPW and the GetPassword() method, the keystrokes you type are not displayed onscreen. In other words, the password gets masked.<\/p>\n<p>Of course, that\u2019s great if you\u2019re running Windows XP or Windows Server 2003. But what if you\u2019re running Windows 2000? How can <i>you<\/i> mask passwords?<\/p>\n<p>Well, some might consider it a bit of a hack, but you can call up a Web page and use the HTML password box to mask passwords. This column isn\u2019t really the place to discuss HTML tagging, so we won\u2019t give you a detailed explanation of how this all works. Instead, we\u2019ll just tell you that you need to do two things. <\/p>\n<p>First, save the following as C:\\Scripts\\Password.htm (and yes, we want this to be an HTML page):<\/p>\n<pre class=\"codeSample\">&lt;SCRIPT LANGUAGE=\"VBScript\"&gt;\n\nSub RunScript\n    OKClicked.Value = \"OK\"\nEnd Sub\n\nSub CancelScript\n    OKClicked.Value = \"Cancelled\"\nEnd Sub\n\n&lt;\/SCRIPT&gt;\n\n&lt;BODY&gt;\n&lt;font size=\"2\" face=\"Arial\"&gt;\nPassword:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;\/font&gt;&lt;font face=\"Arial\"&gt;\n&lt;input type=\"password\" name=\"UserPassword\" size=\"40\"&gt;&lt;\/font&gt;&lt;\/p&gt;\n\n&lt;input type=\"hidden\" name=\"OKClicked\" size = \"20\"&gt;\n\n&lt;input id=runbutton class=\"button\" type=\"button\" value=\" OK \" \nname=\"ok_button\" onClick=\"RunScript\"&gt;\n&amp;nbsp;&amp;nbsp;&amp;nbsp;\n&lt;input id=runbutton class=\"button\" type=\"button\" value=\"Cancel\" \nname=\"cancel_button\" onClick=\"CancelScript\"&gt;\n\n&lt;\/BODY&gt;\n<\/pre>\n<p>Next, save this code as a .vbs file (for example, Password.vbs):<\/p>\n<pre class=\"codeSample\">On Error Resume Next\n\nSet objExplorer = WScript.CreateObject _\n    (\"InternetExplorer.Application\", \"IE_\")\n\nobjExplorer.Navigate \"file:\/\/\/C:\\Scripts\\password.htm\"   \nobjExplorer.ToolBar = 0\nobjExplorer.StatusBar = 0\nobjExplorer.Width = 400\nobjExplorer.Height = 350 \nobjExplorer.Left = 300\nobjExplorer.Top = 200\nobjExplorer.Visible = 1             \n\nDo While (objExplorer.Document.Body.All.OKClicked.Value = \"\")\n    Wscript.Sleep 250                 \nLoop \n\nstrPassword = objExplorer.Document.Body.All.UserPassword.Value\nstrButton = objExplorer.Document.Body.All.OKClicked.Value\nobjExplorer.Quit\nWscript.Sleep 250\n\nIf strButton = \"Cancelled\" Then\n    Wscript.Quit\nElse\n    Wscript.Echo strPassword\nEnd If\n<\/pre>\n<p>So <i>now<\/i> what do you do? Well, start Password.vbs. When you do this a Web page with a password box will pop up on screen. If you type a password and click <b>OK<\/b>, the password you typed will be echoed to the screen (again, just to demonstrate that we\u2019re actually grabbing the password you typed.) If you click <b>Cancel<\/b>, the script will simply end.<\/p>\n<p>If you\u2019re looking for some more practical examples of both ScriptPW and HTML password boxes, you might want to check out the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/templates\/default.mspx\"><b>Remote\/Multiple computer templates<\/b><\/a> found in the Script Center. Here you\u2019ll find sample scripts that don\u2019t simply echo back passwords you enter; instead, they take those passwords and then use WMI\u2019s ConnectServer method or ADSI\u2019s OpenDSObject method to securely connect to remote computers.<\/p>\n<p><\/p>\n<div>\n<table class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"\"><a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/feb05\/hey0204.mspx#top\"><img decoding=\"async\" height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\" \/><\/a><a class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/feb05\/hey0204.mspx#top\">Top of page<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I mask passwords using an InputBox? &#8212; PG Hey, PG. If you\u2019re hoping to mask passwords using a function or method built into WSH or VBScript we\u2019re afraid you\u2019ll be disappointed; neither technology supports password masking. That doesn\u2019t mean you can\u2019t do it, it just means we\u2019ll have to look [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[171,3,4,5,30],"class_list":["post-70503","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-masking-passwords","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-web-pages-and-htas"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I mask passwords using an InputBox? &#8212; PG Hey, PG. If you\u2019re hoping to mask passwords using a function or method built into WSH or VBScript we\u2019re afraid you\u2019ll be disappointed; neither technology supports password masking. That doesn\u2019t mean you can\u2019t do it, it just means we\u2019ll have to look [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=70503"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70503\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=70503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}