首页 > 解决方案 > 有没有办法隐藏/屏蔽vbs中的输入?

问题描述

我正在vbs中制作一个简单的用户名和密码存储程序。输入用户名后,我需要输入密码。但是,我不能,找到一种不以纯文本形式显示输入并将其转换为 ****** 的方法,这就是我已经拥有的:

x=MsgBox("VBScript username and password storage")
username = InputBox("Please enter your username", "Credentials storage", "Your username goes here")
passwd = InputBox("Please enter your password", "Credentials storage", "Your password goes here")

Set obj = CreateObject("Scripting.FileSystemObject")   
Const ForWriting = 2               
Set obj1 = obj.OpenTextFile("test.txt", ForWriting) 
obj1.WriteLine(username & " " & passwd)      
obj1.Close                                                                  
Set obj=Nothing   

我也尝试过这样做,我发现这是另一个问题的答案

Set oInput = CreateObject("ScriptPW.Password")
WScript.StdOut.Write "Enter password: "
pw = oInput.GetPassword

但是当我运行它时它说“ActiveX 组件无法创建对象”ScriptPW.Password“

有没有办法隐藏第 3 行中的文本或解决我的问题?

标签: vbscript

解决方案


玩弄这个,从来没有需要它。到目前为止,我可怜的人的解决方案是这样的。我还不知道是否可以创建一个可以直接在 VBScript 中使用的 powershell 对象,我认为那里有一个固有的障碍,因为 PS 是 .Net。在这种情况下,我仍然将返回的密码Get-Credential作为纯文本返回,所以认为这是一个 hack。它只屏蔽输入框。毫无疑问,有更好的解决方案。从好的方面来说:这段代码非常小,而且 - 重要的是 - 不依赖于 IE。

Option Explicit

Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2
Dim objShell, oExec, strOutput, strPS1Cmd

'create Powershell command
'Note that we manipulate the credentials object into a plain string
strPS1Cmd = "& { $cred = Get-Credential; Write-Output ($cred.Username + '|and-now-comes-the-password-in-plaintext|' + $cred.GetNetworkCredential().Password) } "

' Create a shell and execute powershell, pass the script    
Set objShell = WScript.CreateObject("wscript.shell")
Set oExec = objShell.Exec("powershell -windowstyle hidden -command """ & strPS1Cmd & """ ")

Do While oExec.Status = WshRunning
     WScript.Sleep 100
Loop

Select Case oExec.Status
   Case WshFinished
       strOutput = oExec.StdOut.ReadAll()
   Case WshFailed
       strOutput = oExec.StdErr.ReadAll()
 End Select

WScript.Echo(strOutput)

推荐阅读