第一步:輸入網站訪問帳號(為空則使用默認帳號[IUSR_****]),腳本會自動獲取IUSR帳號,如IUSR帳號被改名則無法獲取,[]中將顯示空。另外如需要用其它帳號作為IIS訪問帳號,則在這裡填入,如不需要更改則直接回車。
第二步:為獲取文件列表及初始化變量,這裡花費時間也比較長。
第三步:設置C盤權限,因文件比較多,另外為防止有個別文件未繼承權限,每一個文件都是重設置了,權限所以運行時間會比較長。
第三步:設置其它盤符時,如不需要,則輸入N退出。
第四步:依次輸入你的網站所在目錄,如不在這裡輸入,則網站目錄將沒有權限訪問。
@echo off
cls
echo ##########################################################
echo # #
echo # 設置磁盤權限 #
echo # Tony www.023.com.cn VPS,服務器租用 #
echo # #
echo # 注意事項: #
echo # #
echo # 1 如需使用PHP請先使用“服務器自主管理工具箱”安 #
echo # 裝再使用此程序設置權限,若手動安裝PHP則需手動 #
echo # 給PHP目錄加上USERS的讀權限再使用此腳本。 #
echo # #
echo # 2 此腳本只給了網站目錄IIS訪問帳戶的修改權限, #
echo # 如需要使用.net需手動加上IIS_WPG組的權限。 #
echo # #
echo # 3 此腳本只適用於網站服務。 #
echo # #
echo # 4 添加修改權限方法:右鍵目錄叵文件--屬性--安全 #
echo # 選擇用戶,在下方法勾上需要的權限。點擊添加-- #
echo # 高級--立即查找,選擇用戶名確定即可添加用戶。 #
echo # #
echo ##########################################################
echo.
rem ====================================得到IUSER帳戶
net user|find /v "命令成功完成"> %windir%tempisUser1.txt 2>nul
echo.> %windir%tempisUser.txt 2>nul
set webUser=
for /f "skip=4 tokens=1" %%i in (%windir%tempisUser1.txt) do echo %%i>> %windir%tempisUser.txt 2>nul
for /f "skip=4 tokens=2" %%i in (%windir%tempisUser1.txt) do echo %%i>> %windir%tempisUser.txt 2>nul
for /f "skip=4 tokens=3" %%i in (%windir%tempisUser1.txt) do echo %%i>> %windir%tempisUser.txt 2>nul
for /f "skip=1" %%i in (%windir%tempisUser.txt) do call:GetIusr %%i
set /p webUser=輸入網站訪問帳號(為空則使用默認帳號[%webUser%]):
del /f /q %windir%tempisUser1.txt
del /f /q %windir%tempisUser.txt
goto endGetIusr
:GetIusr
set webUser1=%1
if /i %webUser1:~0,5%==IUSR_ set webUser=%1
goto :eof
:endGetIusr
REM ===============================獲取C盤文件列表
set /a No=0
set /a No1=0
set /p=初始化程序... <nul
set 退格=
echo y|cacls c: /g administrators:f > nul 2>nul
cacls c: /g system:f /e > nul 2>nul
dir /s /b c: > %windir%tempcacls.txt 2>nul
dir /s /b %windir% > %windir%tempcacls1.txt 2>nul
for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%tempcacls.txt"') do set /a totalNo=%%a
for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%tempcacls1.txt"') do set /a totalNo1=%%a+13
set /p=ok < nul
echo.
REM ===============================開始設置C盤權限
set isGoOn=Y
set /p isGoOn=是否設置C盤權限(Y/N)[Y]:
if /i "%isGoOn%"=="N" goto endSetC
set /p=初始化C盤權限... 0/%totalNo%<nul
for /f "tokens=* delims=" %%i in (%windir%tempcacls.txt) do call:setAcl "%%i"
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=初始化C盤權限... OK <nul
echo.
set /p=設置C盤權限細節... 0/%totalNo1%<nul
for /f "tokens=* delims=" %%i in (%windir%tempcacls1.txt) do call:addUsers "%%i"
cacls "%windir%" /t /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "C:Program FilesCommon FilesODBC" /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "C:Program FilesCommon FilesServices" /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "C:Program FilesCommon FilesSystem" /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "C:Program Files (x86)Common FilesODBC" /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "C:Program Files (x86)Common FilesServices" /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "C:Program Files (x86)Common FilesSystem" /g Users:r /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "%windir%temp" /g Users:c /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "%windir%System32cmd.exe" /r Users /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "%windir%System32cacls.exe" /r Users /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "%windir%System32net.exe" /r Users /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "%windir%System32regsvr32.exe" /r Users /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls "c:php5" /r Users /e /c > nul 2> nul
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... OK <nul
echo.
goto endSetC
:setAcl
set /a No+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=初始化C盤權限... %No%/%totalNo%<nul
set tmpPath=%1
echo y|cacls %1 /g administrators:f > nul 2>nul
cacls %1 /g system:f /e > nul 2>nul
goto :eof
:addUsers
set /a No1+=1
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置C盤權限細節... %No1%/%totalNo1%<nul
cacls %1 /g Users:r /e > nul 2>nul
goto :eof
:endSetC
REM ========================設置其它盤權限
set DiskStr=DEFGHIJKLMNOPQRSTUVWXYZ
set /a DiskNo=23
:GoOnSetDisk
set thisDisk=%DiskStr:~0,1%
set DiskStr=%DiskStr:~1%
set /a DiskNo-=1
set isGoOn=Y
set /p isGoOn=是否設置%thisDisk%盤權限(Y/N)[Y]:
if /i "%isGoOn%"=="N" goto SetOtherDisk
set /p=設置%thisDisk%盤權限... <nul
dir /s /b %thisDisk%: > %windir%tempcacls.txt 2> nul
set /a totalNo=0
set /a No=0
for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%tempcacls.txt"') do set /a totalNo=%%a+1
for /f "tokens=* delims=" %%i in (%windir%tempcacls.txt) do call:setDisk "%%i"
echo y|cacls %thisDisk%: /g administrators:f > nul 2>nul
cacls %thisDisk%: /g system:f /e > nul 2>nul
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置%thisDisk%盤權限... OK <nul
echo.
if %DiskNo% GTR 0 goto GoOnSetDisk
goto endSetDisk
:SetOtherDisk
set isSetOther=Y
set /p isSetOther=是否設置其它盤權限(Y/N)[Y]:
if /i "%isSetOther%"=="N" goto endSetDisk
goto :GoOnSetDisk
:setDisk
set /a No+=1
echo y|cacls %1 /g administrators:f > nul 2>nul
cacls %1 /g system:f /e > nul 2>nul
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置%thisDisk%盤權限... %No%/%totalNo%<nul
goto :eof
:endSetDisk
REM =======================設置網站目錄權限
tony.rings> %windir%tempwebDir.txt 2>nul
: addWebDir
set WebDir=
set /p WebDir=添加網站目錄(為空則添加結束):
if "%WebDir%"=="" goto endAddWebDir
echo %WebDir%>> %windir%tempwebDir.txt 2>nul
goto addWebDir
:endAddWebDir
for /f "tokens=* delims=" %%i in (%windir%tempwebDir.txt) do call:setWebDir "%%i"
goto endSetWebDir
:setWebDir
set /a No=1
set /a totalNo=1
set /p=設置%1權限... <nul
dir /s /b %1> %windir%tempwebSubDir.txt 2>nul
for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%tempwebSubDir.txt"') do set /a totalNo=%%a+1
cacls %1 /t /g %webUser%:c /e /c > nul 2> nul
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置%1權限... 1/%totalNo% <nul
for /f "tokens=* delims=" %%i in (%windir%tempwebSubDir.txt) do call:setWebSubDir "%%i" %1
goto :eof
:setWebSubDir
set /a No+=1
cacls %1 /t /g %webUser%:c /e /c > nul 2> nul
set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%<nul
set /p=設置%2權限... %No%/%totalNo% <nul
goto :eof
:endSetWebDir
del /f /q %windir%tempcacls1.txt
del /f /q %windir%tempcacls.txt
del /f /q %windir%tempwebDir.txt
del /f /q %windir%tempwebSubDir.txt
echo.
echo 恭喜您,設置完成,請按任意鍵退出程序!
pause > nul