@echo off
echo *
echo *
echo ****************************************************
echo *                                                  *
echo *  IIS Server Application Error错误自动修复批处理  *
echo *  http://www.huc08.com                             *
echo *                                                  *
echo ****************************************************
echo *
echo *
set /p isok0=开始IIS修复?(y/n)
if %isok0%==y goto begin
goto forend

:begin
set userIWAM=IWAM_%COMPUTERNAME%
set userIUSR=IUSR_%COMPUTERNAME%

:checkIWAM
net user %userIWAM%
if %errorlevel%==0 goto checkIUSR
goto netuserIWAM

:checkIUSR
net user %userIUSR%
if %errorlevel%==0 goto edituser
goto netuserIUSR

:netuserIWAM
net user
set /p tiwam=请输入正确的“启动 IIS 进程帐户”名称(即以IWAM_开头的帐户名称)?
set userIWAM=%ans%
goto checkIWAM

:netuserIUSR
net user
set /p tiusr=请输入正确的“Internet 来宾帐户”名称(即以IUSR_开头的帐户名称)?
set userIUSR=%tiusr%
goto checkIUSR

:edituser
echo 重置“启动 IIS 进程帐户”密码为123
net user %userIWAM% 123
echo 重置“Internet 来宾帐户”密码为123
net user %userIUSR% 123
echo 密码同步
cscript.exe %HOMEDRIVE%InetpubAdminscriptsadsutil.vbs set w3svc/wamuserpass 123
cscript.exe %HOMEDRIVE%InetpubAdminscriptsadsutil.vbs set w3svc/anonymoususerpass 123
echo *
echo *
set /p isok1=请测试IIS是否正常?(y/n)
if %isok1%==y goto forend

cscript.exe %HOMEDRIVE%InetpubAdminscriptssynciwam.vbs -v
iisreset
echo *
echo *
set /p isok2=请测试IIS是否正常?(y/n)
if %isok2%==y goto forend

echo 清除MSDTC服务注册表相关信息
reg delete HKLMSYSTEMCurrentControlSetServicesMSDTC /f 
reg delete HKLMSOFTWAREMicrosoftMSDTC /f
reg delete HKCRCID /f
echo 停止并重新安装MSDTC服务
net stop msdtc 
msdtc -uninstall 
msdtc -install 
echo 重置“启动 IIS 进程帐户”与“Internet 来宾帐户”密码
net user %userIWAM% 123
net user %userIUSR% 123
echo 同步IIS metabase中IWAM_MYSERVER的密码
%HOMEDRIVE%InetpubAdminscriptsadsutil.vbs set w3svc/wamuserpass "123"
echo 同步COM+应用程序所用的IWAM_MYSERVER密码
cscript.exe %HOMEDRIVE%InetpubAdminscriptssynciwam.vbs -v
echo *
echo *
set /p isok3=请测试IIS是否正常?(y/n)
if %isok3%==y goto forend

echo 重新注册相关组件
rundll32 %windir%system32inetsrvwamreg.dll, CreateIISPackage 
regsvr32 %windir%system32inetsrvasptxn.dll /s
echo *
echo *
set /p isok4=请测试IIS是否正常?(y/n)
if %isok4%==y goto forend

echo *
echo *
echo 如果IIS还不正常的话,我真的解决不了唉,请另请高明吧!

:forend
echo *
echo *
@echo 批处理执行完毕,请按任意键退出?
@echo off 
pause