Help with batch file
Posted: 27 Aug 2013 08:00
Hi,
I am trying to piece together two batch files. The more I look at this the more I get the impression something is not quite right. I am trying to avoid redundant code. I have three sections in the batch file. Cleanup, filemove1 and filemove2. Filemove1 and filemove2 should be activated based upon the system type. The cleanup section should only run once. Can someone tell me how this is wrong and how it should be? Thanks.
If [%ERRORLEVEL%] == [0] (
echo X86
cd %systemroot%\system32
If exist "CleanupCompleted.txt" exit
GOTO CLEANUP
) ELSE (
echo AMD64
cd %systemroot%\sysnative
If exist "CleanupCompleted.txt" exit
GOTO CLEANUP
)
:CLEANUP
REM Get the Altiris Agent install path
FOR /F "tokens=2*" %%A IN ('REG.EXE QUERY "HKLM\Software\Altiris\Altiris Agent" /V "installdir"') DO SET AgentDir=%%B set tempbat=%temp%\AgentClean.bat"
REM Create temporary batch file to execute while the agent restarts echo "%AgentDir%\aexagentutil" /stop > %tempbat% echo rmdir "%AgentDir%\TaskManagement\cache" /s /q >> %tempbat% echo rmdir "%AgentDir%\TaskManagement\status" /s /q >> %tempbat% echo rmdir "%AgentDir%\TaskManagement\statusXml" /s /q >> %tempbat%
REM echo rmdir "%AgentDir%\TaskManagement\lti" /s /q >> %tempbat%
echo ping localhost -n 30 >> %tempbat%
echo "%AgentDir%\aexagentutil" /start >> %tempbat% echo exit >> %tempbat% REM Executes temporary batch file start "" /MIN %tempbat%
Set RegVar=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegVar% 2>NUL | find /I /N "x86">NUL
:FILEMOVE1
COPY /Y "%~dp0\CleanupCompleted.txt" "%systemroot%\system32\CleanupCompleted.txt"
exit
:FILEMOVE2
%systemroot%\sysnative\cmd.exe /c copy /y "%~dp0\CleanupCompleted.txt" "%systemroot%\system32\CleanupCompleted.txt"
exit
I am trying to piece together two batch files. The more I look at this the more I get the impression something is not quite right. I am trying to avoid redundant code. I have three sections in the batch file. Cleanup, filemove1 and filemove2. Filemove1 and filemove2 should be activated based upon the system type. The cleanup section should only run once. Can someone tell me how this is wrong and how it should be? Thanks.
If [%ERRORLEVEL%] == [0] (
echo X86
cd %systemroot%\system32
If exist "CleanupCompleted.txt" exit
GOTO CLEANUP
) ELSE (
echo AMD64
cd %systemroot%\sysnative
If exist "CleanupCompleted.txt" exit
GOTO CLEANUP
)
:CLEANUP
REM Get the Altiris Agent install path
FOR /F "tokens=2*" %%A IN ('REG.EXE QUERY "HKLM\Software\Altiris\Altiris Agent" /V "installdir"') DO SET AgentDir=%%B set tempbat=%temp%\AgentClean.bat"
REM Create temporary batch file to execute while the agent restarts echo "%AgentDir%\aexagentutil" /stop > %tempbat% echo rmdir "%AgentDir%\TaskManagement\cache" /s /q >> %tempbat% echo rmdir "%AgentDir%\TaskManagement\status" /s /q >> %tempbat% echo rmdir "%AgentDir%\TaskManagement\statusXml" /s /q >> %tempbat%
REM echo rmdir "%AgentDir%\TaskManagement\lti" /s /q >> %tempbat%
echo ping localhost -n 30 >> %tempbat%
echo "%AgentDir%\aexagentutil" /start >> %tempbat% echo exit >> %tempbat% REM Executes temporary batch file start "" /MIN %tempbat%
Set RegVar=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegVar% 2>NUL | find /I /N "x86">NUL
:FILEMOVE1
COPY /Y "%~dp0\CleanupCompleted.txt" "%systemroot%\system32\CleanupCompleted.txt"
exit
:FILEMOVE2
%systemroot%\sysnative\cmd.exe /c copy /y "%~dp0\CleanupCompleted.txt" "%systemroot%\system32\CleanupCompleted.txt"
exit