
關于%errorlevel%問題最后由 w3cs 于 -6-26 10:32請教大家個問題,如下代碼:@echo off@echo.@echo Apache service is stoppednet stop apache >nul 2>nulif %errorlevel% equ 0 ( @echo Apache service stopped successfully.) else ( @echo Apache service stopped failed.)@echo.@echo Squid service is stoppednet stop squid >nul 2>nulif %errorlevel% equ 0 ( @echo Squid service stopped successfully.) else ( @echo Squid service stopped failed.)taskkill /f /im httpd.exe >nul 2>nultaskkill /f /im squid.exe >nul 2>nul@echo.reg delete HKEY_LOCAL_MACHINESOFTWAREGNU /f >nul 2>nulC:if not exist C:Apachebin ( @echo C:Apachebin directory does not exist.) else ( sc getkeyname Apache|findstr 1060 >nul 2>nulif %errorlevel% neq 0 (@echo Apache service already dose not exist.) else ( cd C:Apahcebin 2>nul httpd -k uninstall -n Apache >nul 2>nulif %errorlevel% neq 0 ( @echo Apache service uninstall failed.) else ( @echo. @echo Removing the Apache service @echo The Apache service has been removed successfully.)))cdif not exist C:squidsbin ( @echo C:squidsbin directory does not exist.) else ( sc getkeyname Squid|findstr 1060 >nul 2>nulif %errorlevel% neq 0 (@echo Squid service already dose not exist.) else (cd C:squidsbin 2>nulsquid -r >nul 2>nulif %errorlevel% neq 0 ( @echo Squid service uninstall failed.) else ( @echo. @echo Removing the Squid service @echo The Squid service has been removed successfully.)))@pause問題是,apache、squid服務同樣不存在,為什么判斷apache服務時候%errorlevel% ==1,,而判斷squid時候%errorlevel%==0。。測試發現不管squid服務存不存在都是0不是很了解%errorlevel%如何使用?;蚴且陨洗a該如何改進。各位大蝦多多提意見。謝謝了。============================================================================目的:卸載apache服務,1.判斷 C:Apachebin 目錄是否存在如果不存在,顯示目錄不存在,否則繼續2.判斷服務是否存在 如果不存在,顯示服務已不存在,否則繼續3.卸載服務,如果卸載失敗,顯示失敗,成功,顯示卸載成功。卸載squid服務,1.判斷 C:squidsbin 目錄是否存在如果不存在,顯示目錄不存在,否則繼續2.判斷服務是否存在 如果不存在,顯示服務已不存在,否則繼續3.卸載服務,如果卸載失敗,顯示失敗,成功,顯示卸載成功。

