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
Command Prompt Tricks

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

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


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 WinConnections and Microsoft® Exchange Connections

DevConnections, Microsoft® ASP.NET Connections, SharePoint Connections and SQL Server Connections

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

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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!


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