.bat文件夹锁定:如何在Cmd中更改密码

时间:2018-11-21 21:17:24

标签: batch-file cmd

    cls
@ECHO OFF
title Folder posnetki
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST posnetki goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(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 posnetki "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== pass123 goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" posnetki
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md posnetki
echo posnetki created successfully
goto End
:End

如何从cmd而不是代码更改密码?在这里,我确实需要您的帮助,因为我不想每次都想更改密码时需要通过txt打开它。

1 个答案:

答案 0 :(得分:0)

我根本不会专注于您的代码,我只是要演示您的主要问题,即“如何通过脚本更改密码”

>

将密码写入文件方法:

@echo off
cls
:start
if not exist "%temp%\tmppwd.lck" (
  echo password file does not yet exist Please create a Password.
  goto chpwd
)
Choice /C TC /M "Select U to unlock T to test password"
  if %errorlevel%==2 goto chpwd
  if %errorlevel%==1 goto checkpass

:chpwd
set /p "passwd=Enter your new password and press Enter: "
set /p "passwdc=Confirm new password: "
if "%passwd%"=="%passwdc%" (
echo %passwd% > %temp%\tmppwd.lck
goto start
) else (
cls
echo Sorry, Passwords did not match, please retry
goto chpwd
)
:checkpass
for /f %%i in ('type "%temp%\tmppwd.lck"') do set "test=%%i"
set /p "attempt=Enter password to see if this works: "
if "%attempt%"=="%test%" (
  echo Passwords Match & pause
) else (
  echo Sorry, you entered the incorrect password
)

因此,如您所见,我们创建了一个新密码,进行验证,然后将其写入密码文件。如果文件不存在,我们只需进行完全相同的操作即可。

:checkpass标签演示了如何使用文件中的密码。因此,在您当前使用if NOT %pass%== pass123 goto FAIL的地方,我们使用循环读取文件。