vbscript - 有没有办法隐藏/屏蔽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 中使用的 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)
推荐阅读
- javascript - 如何将 Django 变量传递给 Vue 道具
- python-3.x - 如何在向 keras 中的神经网络提供输入的同时使用两个不同的生成器?
- javascript - 标签文本未在 MUIDataTable ReactJS 中更新
- reactjs - 应用到 antd-component 的 styled-components 传递的 CSS 变量在 webpack 在生产模式下编译后消失
- php - WordPress Caldera 表单在验证时显示错误消息
- xamarin - Xamarin iOS - 使用 PlatformEffect 按下时设置按钮的颜色
- c# - 如何在 VR 中为 Unity 设置渲染纹理
- python - 列表索引超出范围?分数
- java - 在 javafx 中拖放一个节点并接受它
- node.js - 使用 PM2 将秘密环境变量传递给 Node 脚本