gpt4 book ai didi

powershell - 如何使用保留名称删除此类文件?

转载 作者:行者123 更新时间:2023-12-04 19:45:38 24 4
gpt4 key购买 nike

大家好,stackoverflow 中的每个人!

我正在寻找如何使用保留名称删除此类文件的解决方法,例如:
(nul, aux, com1, prn, etc...)
所以,我得到了输出错误:

The syntax of the file name, directory or volume incorrect.


@echo off
echo hello world>\\?\"%temp%\nul:nul"
pause
more<"%temp%\nul:nul"
pause
set /p MyVar=<"\\?\%temp%\nul:nul"
echo %MyVar%
Pause
Del "\\?\%temp%\nul:nul" /F
pause

我正在使用这个技巧来存储如下代码所示的密码
所以,我可以将密码设置到这个文件中,也可以从中读取,但我无法删除它。
@echo off
Title %~n0 with colors by Hackoo
Mode 50,5 & Color 0E
Setlocal EnableDelayedExpansion
:CreatePassword
Call :InputPassword "Please choose your password" pass1
Call :InputPassword "Please confirm your password" pass2
If !pass1!==!pass2! ( Goto:Good ) Else ( Goto:Bad )
::***********************************
:InputPassword
Cls
echo.
echo.
set "psCommand=powershell -Command "$pword = read-host '%1' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set %2=%%p
Goto :eof
::***********************************
:Good
Cls
echo.
echo.
Call :Color 0B " Good password " 1
TimeOut /T 2 /NoBreak>nul
Call :Write_Info
Call :Collect_Info
echo Your password stored as : "!SavedPass!" without quotes
pause
Goto :Eof
::***********************************
:Bad
Cls
echo.
echo.
Call :Color 0C " Wrong password try again " 1
TimeOut /T 2 /NoBreak>nul
Goto :CreatePassword
::***********************************
:Color
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
set nL=%3
if not defined nL echo Requires third argument & Pause > nul & goto :Eof
if %3 == 0 (
<nul set /p ".=%BS%">%2 & Findstr /V /A:%1 /R "^$" %2 nul & Del %2 2>&1
goto :Eof
) else if %3 == 1 (
echo %BS%>%2 & Findstr /V /A:%1 /R "^$" %2 nul & Del %2 2>&1
goto :Eof
)
::***********************************
:Write_Info
(echo !Pass2!)>\\?\"%temp%\nul:nul"
Call :Color 0A " Your password is set sucessfuly" 1
::***********************************
:Collect_Info
(set /P SavedPass=)<"\\?\%temp%\nul:nul"
goto :eof
::***********************************

最佳答案

这对我有用:

del "\\.\%temp%\nul"

正如微软所说
https://support.microsoft.com/en-us/kb/120716 ,
您需要使用绕过保留名称检查的语法。

关于powershell - 如何使用保留名称删除此类文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36218119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com