我想知道我的主机文件是否可以使用错误代码访问EDIT,但我总是得到错误代码为0 ..请帮助我获取代码以检查特定指定文件的管理员访问权限< / p>
我正在使用下面的代码,但没有正常工作
@echo off
setlocal enabledelayedexpansion enableextensions
attrib -s -h -r %systemroot%\system32\drivers\etc\hosts
echo %errorlevel%
echo.
IF %errorlevel% NEQ 0 (
echo.
echo Do not have access..
pause >nul
exit
) else (
echo Has Access..
pause >nul
)
答案 0 :(得分:0)
您需要检查文件权限,有很多方法可以通过使用 cacls 命令读取文件和获取文件权限来实现此目的。 *(例如)
@echo off
SETLOCAL EnableDelayedExpansion
findstr /c:"any string" %systemroot%\system32\drivers\etc\hosts
echo %errorlevel%
echo.
if errorlevel 1 (
echo.
echo File Required Administrator Access
pause >nul
exit
) else (
echo Administrator Access ..
pause >nul
)