这是我必须隐藏文件夹的代码。不幸的是,我有朋友不能单独留下我的东西,例如学校项目,家庭照片等。因此,在互联网的帮助下,我设置了这个批处理文件,让我的朋友远离我。问题是它们不是那么愚蠢,所以他们可能会通过点击“编辑”来找出密码。所以我希望我可以帮助设置管理员密码要求来编辑文件。
cls
@ECHO OFF
title Folder Private
if EXIST "HTG Locker" goto UNLOCK
if NOT EXIST Private 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 Private "HTG Locker"
attrib +h +s "HTG Locker"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== Password goto FAIL
attrib -h -s "HTG Locker"
ren "HTG Locker" Private
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Private
echo Private created successfully
goto End
:End
顺便说一下,我是编码的新手,所以我不明白这段代码的一半:Þ
答案 0 :(得分:1)
尝试在需要脚本密码的地方输入类似内容:
runas /user:domain\username "cmd /c rem"
if errorlevel 1 (
echo invalid password
exit /b 666
) else (
attrib -h -s "HTG Locker"
)
甚至更好:
runas /user:domain\username "cmd /c attrib -h -s \"HTG Locker\""
更多RUNAS
答案 1 :(得分:0)
我没有真正回答你的问题,但你可以从这里使用bat to exe转换器:
http://www.f2ko.de/en/b2e.php
这样,您的朋友就无法编辑您的脚本。
编辑:要隐藏一个文件夹,你可以只使用cmd,它只需要一个命令:
attrib +H path\to\folder
答案 2 :(得分:0)
您可以尝试使用此功能,检查管理员:
:CheckAdmin
whoami /groups | findstr /b BUILTIN\Administrators | findstr /c:"Enabled group" && goto :Admin
cls
echo No permissions.
pause
exit /b 1
这将检查批处理文件是否以管理员身份运行。 此外,您需要:
转到:CheckAdmin
在代码的第一行,所以它将是:
cls
@ECHO OFF
title Folder Private
goto :CheckAdmin
:CheckAdmin
whoami /groups | findstr /b BUILTIN\Administrators | findstr /c:"Enabled group" && goto :Admin
cls
echo No permissions.
pause
exit /b 1
:Admin
if EXIST "HTG Locker" goto UNLOCK
if NOT EXIST Private 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 Private "HTG Locker"
attrib +h +s "HTG Locker"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== Password goto FAIL
attrib -h -s "HTG Locker"
ren "HTG Locker" Private
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Private
echo Private created successfully
goto End
:End