ฉันกำลังพยายามเขียนรูทีนย่อยเป็นชุดเพื่อตรวจสอบว่าคอมพิวเตอร์ติดตั้ง Deep freeze หรือไม่ปลอดภัย (สำหรับผู้ที่ไม่ทราบDeep Freezeเป็นโปรแกรมที่ใช้ในการแปลง / ป้องกันและเปลี่ยนแปลงดิสก์ในระบบปฏิบัติการ) dfc.exeเป็นไฟล์ที่ติดตั้งการตรึงแบบลึกที่สามารถใช้เพื่อพิจารณา มันจะคืนค่า 0 ถ้าละลายหรือ 1 ถ้าเป็นน้ำแข็ง
โดยพื้นฐานแล้วฉันคิดว่ามันไม่มีประโยชน์ที่จะเรียกใช้สคริปต์ที่ติดตั้งสิ่งต่าง ๆ หากคอมพิวเตอร์หยุดทำงาน ก่อนอื่นฉันตรวจสอบว่ามีการติดตั้ง dfc.exe หรือไม่จากนั้นฉันพยายามตรวจสอบสถานะการละลาย / แช่แข็ง แต่ปัญหาคือว่าด้วยเหตุผลบางอย่างค่าส่งคืนของ dfc ดูเหมือนจะไม่อัปเดตสำหรับที่ฉันตรวจสอบ errorlevel เป็นครั้งที่สอง
ทุกคนรู้ว่าทำไมฉันไม่เห็นค่าส่งคืนของการตรวจสอบ ErrorLevel ที่สอง ( บรรทัดที่ 41 ) ฉันได้รวมรหัสด้านล่างด้วย
แก้ไข: เพิ่ม Psuedocode สำหรับกระบวนการคิดของฉันก่อนรหัส
::Point1
IF Dfc.exe is present then (
::Point2
If "dfc get /ISFROZEN" returns FROZEN then (
::Point3
Write out to file so we can know that something was skipped,
goto EOF to close out of script and avoid wasting cycles installing
)
::Point4
::Deep freeze is installed, but thawed or it would have gotten caught in the "FROZEN" IF
::Fall through out of outer IF without running anything else
)
::Point5
GOTO (Return to where we left to check if we were wasting time with a label)
รหัสด้านล่างที่นี่
@ECHO Off
::CheckForDF here
ECHO We will now test for DeepFreeze ether not installed or is thawed
Pause
ECHO.
set flagfile=C:\testjava.txt
::Flagfile variable should already be defined before calling this function
Goto :CheckForDF
:DFNotFrozen
ECHO DeepFreeze wasn't installed or is currently thawed
ECHO **Continue with the rest of the script**
ECHO.
PAUSE
GOTO:eof
::***************************
::********Subroutines********
::***************************
:CheckForDF
WHERE dfc >nul 2>&1
::ErrorLEvel 0 means file was found, which means DF is installed
IF %ERRORLEVEL% EQU 0 (
dfc get /ISFROZEN
ECHO %errorlevel%
::ErrorLevel 0 - THAWED and ready to install
::ErrorLevel 1 - FROZEN and pointless to try
IF %errorlevel% EQU 1 (
::Echo out what WOULD have been installed to a file so we could check that the
:: script still ran (and get an idea of how bad we need to unfreeze and log into each computer)
ECHO %flagfile% %date%%time% >> C:\BRCCIT\ScriptsSkippedByDeepFreeze.txt
ECHO ****DeepFreeze is currently frozen****
ECHO.
PAUSE
::Else - DeepFreeze is thawed. return to normal script
goto :EOF
)
::DeepFreeze is thawed, but is installed. We'll just fall through to the not installed result
)
::DeepFreeze Installation not found. Okay to return to normal script
ECHO DeepFreeze is not installed
goto :DFNotFrozen
อัปเดต: ฉันเลิกใช้ IFs ที่ซ้อนกันและกลับไปที่ GOTO และป้ายกำกับ มันไม่ได้สวย แต่รหัสนี้ใช้ได้จริงและในเวลาสิบนาที ฉันเยื้องมันเพื่อสร้างผลภาพของ "รัง" ประดิษฐ์
@ECHO Off
::CheckForDF here
ECHO We will now test for DeepFreeze ether not installed or is thawed
Pause
ECHO.
set flagfile=C:\testjava.txt
::Flagfile variable should already be defined before calling this function
Goto :CheckForDF
:DFNotFrozen
ECHO DeepFreeze wasn't installed or is currently thawed
ECHO **Continue with the rest of the script**
ECHO.
PAUSE
GOTO:eof
::***************************
::********Subroutines********
::***************************
:CheckForDF
WHERE dfc >nul 2>&1
IF %ErrorLevel% EQU 0 Goto :DFInstalled
::ELSE - DF Not found
GOTO :ReturnToScript
:DFInstalled
::DFC.exe get /ISFROZEN
Call ExitWithSpecifiedCode.bat 1
::If Frozen
IF %ErrorLevel% EQU 1 GOTO DFFrozen
::If Thawed
IF %ErrorLevel% EQU 0 GOTO ReturnToScript
:DFFrozen
ECHO %flagfile% %date%%time% >> C:\BRCCIT\ScriptsSkippedByDeepFreeze.txt
ECHO ****DeepFreeze is currently frozen****
ECHO.
PAUSE
::Exit Script Execution
goto :EOF
:ReturnToScript
ECHO ReturnToScript
PAUSE
GOTO (Return to script execution)
IF errorlevel 0พูดThe Syntax of the Command is Incorrectและขัดข้องสคริปต์ โดยเฉพาะฉันแทนที่ IF ที่ตรวจสอบว่ามีการค้นพบไฟล์ระหว่าง Point1 และ Point2 (ฉันแทนที่อันอื่นเช่นกัน แต่สคริปต์ขัดข้องก่อนถึงที่นั่น)
if errorlevel nส่งผ่านเมื่อ errorlevel มากกว่าหรือเท่ากับ n ดังนั้นจึงif errorlevel 0ไม่มีเหตุผล แต่สำหรับส่วนที่การตรวจสอบif errorlevel 1ควรทำงาน