Batch file 批处理中的另一个进程错误中使用的文件

Batch file 批处理中的另一个进程错误中使用的文件,batch-file,Batch File,我已经批量创建了一个程序,要求输入密码以继续执行程序的下一部分。我创建了一个包含密码的文件。在程序中,我让它调用该文本文件的内容,并将其设置为一个变量,即“密码”。。。唯一的问题是,我收到一个错误,上面说:“该文件正在另一个进程中使用” 这是我的代码中找到错误的部分: for /F "delims=" %%i in (Password.txt) do set content=%%i echo %content% set password123=%content% powershell -Comm

我已经批量创建了一个程序,要求输入密码以继续执行程序的下一部分。我创建了一个包含密码的文件。在程序中,我让它调用该文本文件的内容,并将其设置为一个变量,即“密码”。。。唯一的问题是,我收到一个错误,上面说:“该文件正在另一个进程中使用”

这是我的代码中找到错误的部分:

for /F "delims=" %%i in (Password.txt) do set content=%%i echo %content% set password123=%content%
powershell -Command $pword = read-host "Enter password" -AsSecureString ; ^ $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; ^ [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt
set /p password=<.tmp.txt & del .tmp.txt
if %password123%=%password% goto :correct
if not %password123%=%password% goto :incorrect
for/F“delims=“%%i in(Password.txt)do set content=%%i echo%content%set password123=%content%
powershell-命令$pword=读取主机“输入密码”-AsSecureString;^$BSTR=[System.Runtime.InteropServices.Marshall]::SecureStringToBSTR($pword);^[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)>.tmp.txt

set/p password=绕过创建包含临时文件的密码。分析powershell
输出,例如如下所示:

for /F "delims=" %%G in ('
powershell -NoProfile -Command "$pword = read-host 'Enter password' -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"
') do (
    set "password=%%G"
)
SETLOCAL EnableDelayedExpansion
if "!password123!"=="!password!" ( 
  ENDLOCAL
  goto :correct
) else ( 
  ENDLOCAL
  goto :incorrect
)
如果/?,也要读取整个
;使用适当的比较运算符
==
。使用双引号转义密码中可能出现的
cmd
-有毒字符,如
|&

if "%password123%"=="%password%" ( goto :correct ) else goto :incorrect
要正确处理密码中可能出现的双引号,请按如下方式应用:

for /F "delims=" %%G in ('
powershell -NoProfile -Command "$pword = read-host 'Enter password' -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"
') do (
    set "password=%%G"
)
SETLOCAL EnableDelayedExpansion
if "!password123!"=="!password!" ( 
  ENDLOCAL
  goto :correct
) else ( 
  ENDLOCAL
  goto :incorrect
)