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

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

问题描述

我有一个包含批处理文件的脚本,这些文件会生成Powershell脚本.我已经开始通过VB Script完成相同的任务.到目前为止,我已经为字符串分配了大部分信息.但是我想提示输入一个密码,该密码存储为安全字符串,并且可以输出到文本文件中,以便以后在其他脚本中使用.到目前为止,我发现的唯一代码不起作用,我认为可能是因为它是针对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\reports\input.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天全站免登陆