如何在 VB 脚本中为安全字符串分配密码

2024-01-03

我有一个由生成 powershell 脚本的批处理文件组成的脚本。我自己通过 VB 脚本完成了同样的任务。到目前为止,我已经将所需的大部分信息分配给了字符串。但我希望提示输入密码,该密码存储为安全字符串,并且可以输出到文本文件以供以后在进一步的脚本中使用。到目前为止,我发现的唯一代码不起作用,我想可能是因为它是针对 VB 而不是 VBS 的。非常感谢任何帮助。

之前使用的powershell代码是。

    echo Please enter admin credentials (This will be stored in a secure string:
    powershell -Command "& { read-host -assecurestring | convertfrom- securestring | out-file C:\S3BS\reports\input.txt; } "

您可以将这段小代码与 powershell 和批处理一起使用

@ECHO OFF
Title Type a password with powershell and batch
:CheckPassword
Mode con cols=50 lines=3
cls & color 0A & echo.
set MyPassword=Hackoo
set "psCommand=powershell -Command "$pword = read-host 'Enter your password' -AsSecureString ; ^
    $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
        [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
if %MyPassword%==%password% (Goto:Good) else (Goto:Bad)
exit/b
::***********************************************************************************************
:Good
Cls & Color 0A
echo(
echo                   Good Password
TimeOut /T 2 /NoBreak>nul
Exit
::***********************************************************************************************
:Bad
Cls & Color 0C
echo(
echo                   Bad password
TimeOut /T 1 /NoBreak>nul
Goto:CheckPassword
::***********************************************************************************************
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 VB 脚本中为安全字符串分配密码 的相关文章

随机推荐