Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


October 22, 2001

Rem: Masking Passwords in Scripts


RSS
View this exclusive article with VIP access -- click here to join |
See More VBScript Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

Do you have a scripting-related question or problem? You can send your question or problem to winscriptsol@win2000mag.com.

I need to create a script that prompts the operator for a password. I know that I can use VBScript's InputBox function or the WScript object's StdIn property in Windows Script Host (WSH) to prompt the user. However, both InputBox and StdIn display the password as the user types it. I prefer to mask the password. Does VBScript or WSH provide a way to mask passwords?

Neither VBScript nor WSH can mask passwords. However, Windows .NET Server (formerly code-named Whistler) and Windows XP include a new password component, scriptpw.dll, that provides this functionality. Script-pw.dll is a standard system component that resides in the \%system root%\ system 32 directory.

Listing 1 illustrates how you can use scriptpw.dll to retrieve a user's password without displaying the password as the user types it. The script begins by creating an instance of the Password object using VBScript's Create-Object function with the password component's programmatic identifier (ProgID), ScriptPW.Password. . . .


Already a VIP member?
Please log on to view the full article

Why become a VIP member?

VIP-only online access
VIP CD delivered twice a year: offline access to the entire Windows IT Pro article library
Monthly issue of your choice of Windows IT Pro or SQL Server Magazine

Subscribe Now
Reader Comments
<P>While this works for the CScript host, what I'm looking for is something similar that I can run under the WScript host. There must be something suitable somewhere!</P>

Andrew Good September 01, 2003


<P>Where can you find that .dll? I searched my XP Pro CD-ROM and it does not appear. Am I missing something here?</P>

Rhino March 05, 2004


To Andrew:

You need to force your script to run under CScript. I found this online, and it works for me:

Sub Force(sScriptEng)
' Forces this script to be run under the desired scripting host.
' Valid sScriptEng arguments are "wscript" or "cscript".
' If you don't supply a valid name, Force will switch hosts.

If Lcase(Right(Wscript.FullName, 12)) = "\wscript.exe" Then
'WScript.Echo "Running under WSCRIPT"
If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then
'Need to switch to CSCRIPT
CreateObject("Wscript.Shell").Run "cscript.exe " & Chr(34) & Wscript.ScriptFullName & Chr(34)
Wscript.Quit
End If
Else
'WScript.Echo "Running under CSCRIPT"
If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then
'Need to switch to WSCRIPT
CreateObject("Wscript.Shell").Run "wscript.exe " & Wscript.ScriptFullName
Wscript.Quit
End If
End If
end sub

Force "csript"

hypert September 16, 2004 (Article Rating: )


Well, the formatting of that code looks great, doesn't it?

Let me try to force linebreaks in there:

Sub Force(sScriptEng)

' Forces this script to be run under the desired scripting host.

' Valid sScriptEng arguments are "wscript" or "cscript".

' If you don't supply a valid name, Force will switch hosts.

If Lcase(Right(Wscript.FullName, 12)) = "\wscript.exe" Then

'WScript.Echo "Running under WSCRIPT"

If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then

'Need to switch to CSCRIPT

CreateObject("Wscript.Shell").Run "cscript.exe " & Chr(34) & Wscript.ScriptFullName & Chr(34)

Wscript.Quit

End If

Else

'WScript.Echo "Running under CSCRIPT"

If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then

'Need to switch to WSCRIPT

CreateObject("Wscript.Shell").Run "wscript.exe " & Wscript.ScriptFullName

Wscript.Quit

End If

End If

end sub

Force "cscript"


hypert September 16, 2004 (Article Rating: )


salut

Anonymous User December 28, 2004


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Global Trends: Unified SOA Performance Management Matters

The role of Service Level Agreements in Successful SOA Deployments

Related Events Top 11 Reasons Why Oracle Database 11g on Windows is Right For You

Windows, Unix, Linux Interoperability

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement