【发布时间】:2017-05-15 22:16:19
【问题描述】:
cls
@ECHO OFF
title Folder Secure
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Secure goto MDLOCKER
:CONFIRM
echo (Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Secure "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
set/p "variable=>"
if NOT %variable%== (Here is Enter Your Password) goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Secure
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Secure
echo Secure created successfully
goto End
:End
这是我的 Echo 代码,用于使用命令隐藏文件夹,y/n 并使用密码取消隐藏。它工作正常,我认为没有错误。
但问题是,我需要批处理文件来用 * 屏蔽输入文本。
我在以下位置找到了它:
batch file to mask input with * without an external file
这是 Matt Williamson 在批处理文件中使用 Powershell 的一种方法
set "psCommand=powershell -Command "$pword = read-host 'Enter 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=%%pass
在这个奇妙的解决方案之后,它可以很好地掩盖我的文字。 但是经过一些修改后,我无法理解将密码放在哪里?
谁来帮帮我!!我在批处理文件中将密码放在哪里?
这是最终代码:
cls
@ECHO OFF
title Folder Secure
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Secure goto MDLOCKER
:CONFIRM
echo (Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Secure "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
set "psCommand=powershell -Command "$pword = read-host 'Enter 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=%%pass
if NOT %pass%== folder goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Secure
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Secure
echo Secure created successfully
goto End
:End
但它不接受我的密码。 我对Powershell一无所知!
【问题讨论】:
-
将
do set password=%%pass更改为do set pass=%%p -
您确实意识到这根本不提供任何安全性,是吗?
-
您好,我是新人,对不起。复制!!但我前后搜索这些网站!但我无法理解...
-
@MathiasR.Jessen 它仍然无法正常工作...您能完整检查我的最终代码并将其保存在您的电脑上吗?它是否适合您?
标签: powershell batch-file hide mask