如何在 VB 脚本中为安全字符串分配密码 [英] How to assign password to secure string in VB Script

查看:30
本文介绍了如何在 VB 脚本中为安全字符串分配密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a script comprising of batch files that generate powershell scripts. I've taken it upon myself to accomplish the same task via VB Script. So far I've assigned most of the info I need to strings. But I would like to have a prompt for a password that is stored as a secure string and can be outputted to a text file for later use in further scripts. So far the only code I've found doesn't work I think perhaps because it was intended for VB rather than VBS. Any help greatly appreciated.

之前使用的powershell代码是.

The powershell code previously used was.

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

推荐答案

这个小代码可以配合powershell和batch使用

You can use this small code with powershell and batch

@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
::***********************************************************************************************

这篇关于如何在 VB 脚本中为安全字符串分配密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆