I am new to bat script. I want below script to check if web is up and if not restart the coldfusion and save all info into log file.
#REM Remove any existing files.
del C:\Users\Administrator\check.txt
#REM to download file
wget -O check.txt --no-check-certificate https://10.2.3.30/ebanking/ch/en-en/index.cfm
#REM Search for the term in the previously downloaded file.
FINDSTR /C:"index.cfm" check.txt
if errorlevel equ 1 notfound
found
cls
:notfound
echo notfound > log.txt
echo stopping ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
echo starting ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
cls
exit
:found
echo found >> log.txt
cls
exit
You missed goto command for the label notfound. For logic, I swapped label between notfound/found
#echo off
pushd "C:\Users\Administrator"
#REM Remove any existing files.
del check.txt
#REM to download file
wget -O check.txt --no-check-certificate https://10.2.3.30/ebanking/ch/en-en/index.cfm
#REM Search for the term in the previously downloaded file.
FINDSTR /C:"index.cfm" check.txt
if errorlevel equ 1 (goto notfound)
:found
echo found >> log.txt
exit /b 0
:notfound
echo notfound > log.txt
echo stopping ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
echo starting ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
exit
you could simplify the code to the following in a loop
#echo off
set "someurl=https://10.2.3.30/ebanking/ch/en-en/index.cfm"
:loop
wget --server-response -nv --spider %someurl% 2>&1 | find "HTTP/1.1 200 OK">nul
if errorlevel 1 (
echo %DATE% %TIME%: stopping ebanking>> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
timeout 5>nul
echo %DATE% %TIME%: starting ebanking>> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
) else (
echo %DATE% %TIME%: site is up>> log.txt
)
rem Wait 1 hour before loop
timeout 3600
goto loop
Related
I was making a .bat code to send .txt files to a specific folder on my ftp server. But I also wanted a way to check if these files were really uploaded. I searched a lot on the internet and unfortunately, I realized that it can't be done using .bat command.
So I tried using another way: The .bat will send the files and then will take it back to the folder, if the file already exists in the folder it will show a message that the file was successfully uploaded.
I did this script below, but the part of the "checking if was uploaded" is not working right.
Someone can help me?
#echo off
#setlocal enableextensions
#cd /d "%~dp0"
mode 34,12
color 0a
Ping www.google.nl -n 1 -w 1000 >nul 2>nul
if errorlevel 1 (set internet=Nao foi possivel se conectar ao servidor) else (set internet=Conectado) >nul 2>nul
echo %internet%
if "%internet%"=="No connection" goto 1
if "%internet%"=="Conected" goto 2
:1
echo No connection
echo.
echo Try later...
echo.
pause
exit
:2
( echo open ftp.xxxxxxxxxxx.com
echo xxxxxxx
echo xxxxxxx
echo ascii
echo lcd "c:\Vendas Pay&Go\files"
echo cd "Vendas Cartões Pay&Go"
echo cd "ECO"
echo mput *.txt
echo bye
)> %temp%\ftpsend.dat
ftp -i -s:%temp%/ftpsend.dat >nul 2>nul
del /f /s /q %temp%\ftpsend.dat >nul 2>nul
( echo open ftp.xxxxxxx.com
echo xxxxxxx
echo xxxxxxx
echo ascii
echo lcd "c:\Vendas Pay&Go\files"
echo cd "Vendas Cartões Pay&Go"
echo cd "ECO"
echo mget *.txt
echo bye
)> %temp%\ftpsend.dat
ftp -i -s:%temp%/ftpsend2.dat >nul 2>nul
del /f /s /q %temp%\ftpsend2.dat >nul 2>nul
if %*.txt% exist goto3
:4
echo File was not uploaded
pause
:3
echo File Uploaded.
del /s /f /q "c:\Vendas Pay&Go\files\*.txt"
If you want to conditional execution to display a message you can do something like this. The && means the previous command was successful. The || means the previous command was not successful.
(ftp -i -s:%temp%/ftpsend.dat | find /I "file successfully transferred" >nul) && (echo File Successfully Transferred) || ( echo File not transferred. Tray again later.)
Updated version based on comment below
(ftp -i -s:%temp%/ftpsend.dat | find /I "file successfully transferred" >nul) && (
echo File successfully sent.
del /f /s /q "c:\Vendas Pay&Go\files\*.txt" >nul
) || (
cls
echo File not uploaded. Try later.
)
Playing around with my Batch script again. It was brought to my attention that my update routine was not working correctly. Iteration 1 would result in the running script being deleted and not copying the new version from a folder I had selected. Iteration 2 now deletes the old script and copies the new script but with each line of code I change I end up with the currently running script closing, and the new updated script not launching.
Here's a snippet of the Update routine:
:Options
REM I'll set the variable here to what is set elsewhere in the script.
SET VERSION=Version 1.7
CLS
ECHO.
ECHO.
ECHO %VERSION%
ECHO.
ECHO.
ECHO ==================== OPTIONS =====================
ECHO.
ECHO 1. Update Script WIP
ECHO 2. Install entire script to Statup Folder
ECHO 3. Install individual items for auto-launch
ECHO 4. Install Windows Logout feature
ECHO 5. Uninstall
ECHO 6. Change Colors
ECHO 7. Changelog
ECHO.
ECHO =======PRESS 'Q' TO QUIT OR 'B' TO GO BACK========
ECHO.
SET OPTION=
SET /P OPTION=Select an Option:
IF /I '%OPTION%'=='1' GOTO Update
IF /I '%OPTION%'=='2' GOTO Install
IF /I '%OPTION%'=='3' GOTO I_Install
IF /I '%OPTION%'=='4' GOTO I_Logout
IF /I '%OPTION%'=='5' GOTO Uinstall
IF /I '%OPTION%'=='6' GOTO Colors
IF /I '%OPTION%'=='7' GOTO Changelog
IF /I '%OPTION%'=='q' GOTO quit
IF /I '%OPTION%'=='quit' GOTO quit
IF /I '%OPTION%'=='b' GOTO menu
IF /I '%OPTION%'=='back' GOTO menu
ECHO.
ECHO ============INVALID INPUT============
ECHO Please select a number
ECHO or select 'Q' or 'B'.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO Options
:Update
ECHO.
IF EXIST "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" (
GOTO Update_1
) ELSE (
ECHO You have not installed the script yet. Please install the script first.
)
PAUSE
GOTO Options
:Update_1
IF EXIST "%userprofile%\AppData\Local\Temp\Update.bat" (
GOTO Update_2
) ELSE (
REM Here the main script writes an update script to a batch file
ECHO DEL "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" > "%userprofile%\AppData\Local\Temp\Update.bat"
REM I replaced the original file location with one on the desktop. The original location was on a network drive, location is confidential.
ECHO COPY "%userprofile\Desktop\Shortcut Browser *.bat" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup" >> "%userprofile%\AppData\Local\Temp\Update.bat"
ECHO CALL "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" >> "%userprofile%\AppData\Local\Temp\Update.bat"
ECHO EXIT >> "%userprofile%\AppData\Local\Temp\Update.bat"
)
GOTO Update_2
REM Here the main script calls upon the update script
:Update_2
CALL "%userprofile%\AppData\Local\Temp\Update.bat"
REM The script seems to hang here. Either both the scripts will remain open or close or a combination depending on where CALL and START were used.
PAUSE
GOTO Options
I saw elsewhere I could have used the FC command. I didn't know about it until troubleshooting this problem. I've gotten this far and I feel I'm just missing some small trick to get the new updated script to launch.
If you need any more info let me know. I think I covered everything.
#ECHO OFF
SETLOCAL
TITLE Super Script 5000
:Options
REM I'll set the variable here to what is set elsewhere in the script.
SET VERSION=Version 1.7
CLS
ECHO.
ECHO.
ECHO %VERSION%
ECHO.
ECHO.
ECHO ==================== OPTIONS =====================
ECHO.
ECHO 1. Update Script WIP
ECHO 2. Install entire script to Statup Folder
ECHO 3. Install individual items for auto-launch
ECHO 4. Install Windows Logout feature
ECHO 5. Uninstall
ECHO 6. Change Colors
ECHO 7. Changelog
ECHO.
ECHO =======PRESS 'Q' TO QUIT OR 'B' TO GO BACK========
ECHO.
SET "OPTION="
SET /P "OPTION=Select an Option: "
IF /I "%OPTION%"=="1" GOTO Update
IF /I "%OPTION%"=="2" GOTO Install
IF /I "%OPTION%"=="3" GOTO I_Install
IF /I "%OPTION%"=="4" GOTO I_Logout
IF /I "%OPTION%"=="5" GOTO Uinstall
IF /I "%OPTION%"=="6" GOTO Colors
IF /I "%OPTION%"=="7" GOTO Changelog
IF /I "%OPTION%"=="q" GOTO quit
IF /I "%OPTION%"=="quit" GOTO quit
IF /I "%OPTION%"=="b" GOTO menu
IF /I "%OPTION%"=="back" GOTO menu
ECHO.
ECHO ============INVALID INPUT============
ECHO Please select a number
ECHO or select 'Q' or 'B'.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO Options
:Update
ECHO.
IF EXIST "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" (
GOTO Update_1
) ELSE (
ECHO You have not installed the script yet. Please install the script first.
)
PAUSE
GOTO Options
:Update_1
IF EXIST "%tmp%\update.bat" (
2>NUL DEL "%tmp%\update.bat" || GOTO Options
)
SETLOCAL
FOR %%A IN (
"%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat"
) DO (
SET "old_version=%%~A"
SET "old_dir=%%~dpA"
SET "old_file=%%~nxA"
)
FOR %%A IN (
"%userprofile%\Desktop\Shortcut Browser *.bat"
) DO (
SET "new_version=%%~A"
SET "new_dir=%%~dpA"
SET "new_file=%%~nxA"
)
IF NOT DEFINED old_version (
ENDLOCAL
GOTO Options
) ELSE IF NOT DEFINED new_version (
ENDLOCAL
GOTO Options
)
(
ECHO #ECHO OFF
ECHO SETLOCAL
ECHO.
ECHO ECHO Update and restarting...
ECHO ^>NUL PING localhost -n 3
ECHO.
ECHO SET "old_version=%old_version%"
ECHO SET "new_version=%new_version%"
ECHO SET "updated_version=%old_dir%\%new_file%"
ECHO.
ECHO CALL :log /clear_log
ECHO.
ECHO IF NOT EXIST "%%new_version%%" (
ECHO CALL :log ERROR: Not exist "%%new_version%%".
ECHO EXIT /B 1
ECHO ^)
ECHO.
ECHO CALL :log Move old_version to old_version.bak.
ECHO MOVE "%%old_version%%" "%%old_version%%.bak" ^|^| (
ECHO CALL :log ERROR: Move failed to backup old version.
ECHO EXIT /B 2
ECHO ^)
ECHO.
ECHO CALL :log Copy new_version to old_version.
ECHO COPY "%%new_version%%" "%%appdata%%\Microsoft\Windows\Start Menu\Programs\Startup\" ^|^| (
ECHO CALL :log ERROR: Copy failed. Restore old version.
ECHO MOVE "%%old_version%%.bak" "%%old_version%%" ^|^| (
ECHO CALL :log ERROR: Restore old version failed.
ECHO EXIT /B 3
ECHO ^)
ECHO EXIT /B 4
ECHO ^)
ECHO.
ECHO CALL :log Delete old_version.bak.
ECHO DEL "%%old_version%%.bak" ^|^| (
ECHO CALL :log WARNING: Delete backup file failed.
ECHO ^)
ECHO.
ECHO IF NOT EXIST "%%updated_version%%" (
ECHO CALL :log ERROR: Not exist: "%%updated_version%%"
ECHO EXIT /B 5
ECHO ^)
ECHO.
ECHO ENDLOCAL
ECHO.
ECHO ECHO Ready to restart updated version
ECHO PAUSE
ECHO CALL "%old_dir%\%new_file%"
ECHO EXIT /B
ECHO.
ECHO :log
ECHO SETLOCAL
ECHO SET "log=%%tmp%%\update.log"
ECHO IF /I "%%~1"=="/clear_log" TYPE NUL ^> "%%log%%" ^& EXIT /B
ECHO IF /I "%%~1"=="/delete_log" 2^>NUL DEL "%%log%%" ^& EXIT /B
ECHO SET args=%%*
ECHO IF NOT DEFINED args EXIT /B
ECHO ECHO %%*
ECHO ^>^> "%%log%%" ECHO %%*
ECHO EXIT /B
) > "%tmp%\update.bat"
ENDLOCAL
START "Super Script 5000" "cmd /c "%tmp%\update.bat""
EXIT
:Quit
Tested on a Win7 VM. The script needs to restart on update else
weird issues may occur. CMD does not like scripts changing as it
is reading and interpreting them. Even reusing the same console
using START with /B may cause key input issues.
update.bat is overwritten every update as it stores absolute paths
so each update will be different paths with the filenames changing.
Using a wildcard with CALL may not work too well otherwise.
update.bat moves the old version to a .bak file, copies the new
version and if successful, deletes the .bak file, else moves the
.bak file to the old version. This is just to ensure a current
version always exists even if the update fails.
Changed quotes in :Options label from ' to ". Quotes are not
interchangeable like some other languages. Example: "%OPTION%"
will work if contains a space though '%OPTION%' may cause error.
I notice no SETLOCAL at the top of your full script. Advise you add
it unless you have a good reason not to.
I merged labels :Update_1 and :Update_2 into one.
Perhaps adjust Ping localhost -n number if more or less time is
needed.
Look at the %tmp%\update.log if a problem happens. Though expect
the errors to show in the console as the label :log in
update.bat echoes to console and writes to the log.
I have been having the hardest time with this FOR loop. I thought it was working the other day, but when I went to use it today, it didn't. This is part of a much larger script, but this is the only portion that is hanging me up. Also, to note, I did not write the majority of the script. It was given to me, and I have had to modify it to fit my needs. Can someone take a look and let me what I am missing.
IF NOT EXIST C:\Paytronix\config\deploytool\terminals.xml (
copy terminals.xml_template terminals.xml > temp.txt
set MAKETERMXML=1
) ELSE (
set MAKETERMXML=0
)
echo Create terminals.xml = %MAKETERMXML%
PING localhost -n 5 >NUL
for /l %%T in (1,1,%TERMINALS%) do (
echo Trying terminal %TERMSTRING%%%T
PING localhost -n 5 >NUL
REM net use /user:USERNAME /PERSISTENT:NO P: \\%TERMSTRING%%%T\C$ PASSWORD
net use P: \\%TERMSTRING%%%T\C$ /USER:%USR% %PWRD% /PERSISTENT:NO > temp.txt
REM /USER:username password (Insert after C$
REM net use P: \\%TERMSTRING%%%T\C$ /PERSISTENT:NO > temp.txt
setlocal EnableDelayedExpansion
echo Copying Installer Shortcut to Startup Folder
IF EXIST "\\%TERMSTRING%%%T\C$\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" (
copy aaaPxAlohaUiInstaller.lnk "\\%TERMSTRING%%%T\C$\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" > result.txt
) ELSE (
copy aaaPxAlohaUiInstaller.lnk "\\%TERMSTRING%%%T\C$\Documents and Settings\All Users\Start Menu\Programs\Startup" > result.txt
)
PING localhost -n 5 >NUL
find /c "1" result.txt > copyresult.txt
FOR /F "tokens=1,2,3" %%a in (copyresult.txt) do set COPYTAG=%%c
echo Copy Result = !COPYTAG!
PING localhost -n 5 >NUL
IF !COPYTAG!==1 (
echo SUCCESS !!! Valid Terminal %TERMSTRING%%%T > C:\Paytronix\Paytronix.bd
echo SUCCESS !!! Valid Terminal %TERMSTRING%%%T
echo Updating PxInst folder
IF NOT EXIST "\\%TERMSTRING%%%T\C$\PxInst\" mkdir \\%TERMSTRING%%%T\C$\PxInst > temp.txt
REM Delete PxInst contents
del /F /S /Q "\\%TERMSTRING%%%T\C$\PxInst\*" > temp.txt
REM Create PxAlohaUiInstaller folder
IF NOT EXIST "\\%TERMSTRING%%%T\C$\PxInst\PxAlohaUiInstaller" mkdir \\%TERMSTRING%%%T\C$\PxInst\PxAlohaUiInstaller > temp.txt
REM Update user program installer
copy /Y C:\Paytronix\PxAlohaUiInstaller\PxAlohaUiInstaller.exe \\%TERMSTRING%%%T\C$\PxInst\PxAlohaUiInstaller > temp.txt
REM Copy PxAlohaUiInstaller done
PING localhost -n 5 >NUL
REM Create user program dir if missing
IF NOT EXIST "\\%TERMSTRING%%%T\C$\Paytronix" (
echo Creating User Program folder
mkdir \\%TERMSTRING%%%T\C$\Paytronix\config\userprog > temp.txt
copy C:\Paytronix\config\userprog\pxalohaui.cfg \\%TERMSTRING%%%T\C$\Paytronix\config\userprog\ > temp.txt
)
::echo
IF %MAKETERMXML%==1 (
echo ^<Terminal^> >> terminals.xml
echo ^<Name^>term%%T^</Name^> >> terminals.xml
echo ^<Path^>\\%TERMSTRING%%%T\C$^</Path^> >> terminals.xml
echo ^<Address^>%TERMSTRING%%%T^</Address^> >> terminals.xml
echo ^</Terminal^> >> terminals.xml
)
)
endlocal
net use P: /DELETE /YES > temp.txt
del result.txt
del copyresult.txt
del temp.txt
)
echo %MAKETERMXML%
IF %MAKETERMXML%==1 (
echo ^</TerminalList^> >> terminals.xml
echo ^</PaytronixConfig^> >> terminals.xml
copy terminals.xml C:\Paytronix\config\deploytool\terminals.xml
)
I wrote a windows batch script to check and move files to another directory based on the list I put in a notepad file named list.txt. But I have no idea that how to set the while-loop. Only to jump out of the subroute when the condition fulfill.
In C Programming, we could write like this by setting a while-loop direcly. But seems in windows batch is quite different.
All I want is like this:
Directory A:
1. A.txt
2. B.txt
3. list.txt (By line sequential with filename want to move)
4. process.bat
Directory B:
None of files (Then move a file by order of line set in list.txt) OR
A.txt (If already existed a text file in directory, process.bat will pause before A.txt disappear)
Process.bat
#echo off
:readline
for /f "tokens=*" %%a in (list.txt) do call :processline %%a
goto :eof
:processline
if exist D:\DirectoryA\*.txt (
echo %time% >> D:\AutoLog\Log.txt
echo Previous job did not finished yet. >> D:\AutoLog\Log.txt
Timeout /t 30
echo.
)
set name=%*
if exist %name%.txt (
echo %time% >> D:\AutoLog\Log.txt
echo File found and processing %name%.txt now... >> D:\AutoLog\Log.txt
copy "%~dp0\%name%.txt" "D:\DirectoryB"
echo Transfer %name%.txt completed!! >> D:\AutoLog\Log.txt
echo. >> D:\AutoLog\Log.txt
Timeout /t 790
echo.
echo ==============================================================
)
:eof
Please guide me to finish the script by using a while-loop method. Thanks
I change some script sequence and it works now.
#echo off
:readline
for /f "tokens=*" %%a in (list.txt) do call :processline %%a
goto :eof
:processline
set name=%*
if exist C:\Test2\*.txt (
echo %date% %time% >> C:\Test2\Log.txt
echo Previous job did not finished yet. >> C:\Test2\Log.txt
Timeout /t 5
echo.
echo. >> C:\Test2\Log.txt
goto :processline
)
if exist %name%.txt (
echo %date% %time% >> C:\Test2\Log.txt
echo File found and processing %name%.txt now... >> C:\Test2\Log.txt
copy "%~dp0\%name%.txt" "C:\Test2"
echo Transfer %name%.txt completed!! >> C:\Test2\Log.txt
echo. >> C:\Test2\Log.txt
Timeout /t 10
echo.
echo ==============================================================
)
:eof
This will copy as well as count the number of lines from your text file..
# echo off
:TextPath
cls
set /p Input=#1 Enter the full path of the text file :
set /p Source=#2 Enter the full path of Source :
set /p Target=#3 Enter the full path of Destination :
:choice
set /P c=Ready to Continue[Y/N]?
if /I "%c%" EQU "Y" goto :Yes
if /I "%c%" EQU "N" goto :No
goto :choice
:Yes_Local
for /f "delims=" %%i in (%Input%) do echo f| xcopy /f /y "%Source%\%%i" "%Target%\%%i"
for /f %%C in ('Find /V /C "" ^< %Input%') do set Count=%%C
msg * No of Lines executed= %Count%
exit
:No
cls
color e
echo Redirecting to Main....
PING 127.0.0.1 -n 2 >NUL
cls
echo Please wait
PING 127.0.0.1 -n 4 >NUL
goto TextPath
I am trying to run a file in order to grab the IP after I ping a list of host file names.
When I try to run it I get the error that "this process cannot be access because the file is being used by another process"
What can I do to fix it?
#ECHO OFF
COLOR 1f
:HEADER
CLS
ECHO -------------------------------------------------------------------------------
ECHO AUTHOR: Levon Becker
ECHO TITLE: Ping-List
ECHO LAST CHANGE: 04/08/2010
ECHO VERSION: 1.002
ECHO LINK: http://wiki.bonusbits.com/main/BatchScripts:Ping_List
ECHO -------------------------------------------------------------------------------
ECHO.
PAUSE
:NOTES
REM +The text file with your list of hostnames should be named hostlist.txt
REM +The hostnames can be seperated by a comma or carriage return
REM +The output file will be a text file named PingResults.txt
REM +The output file is setup to be comma delimited for easy import to Excel
REM +Changed output file to be csv
REM Delete the output file if it exists from a previous run.
IF EXIST "PingResults.txt" del /q PingResults.txt
REM Delete the temp file.
IF EXIST "pinglog" del /q pinglog
REM Description Header for top row in Excel
ECHO Hostname,IP from Ping,Ping Status,Data of Ping,Time of Ping > PingResults.csv
REM Pull hostnames from text file until the end of the text file list
for /f "tokens=* delims=," %%I in (hostlist.txt) do call :sub1 %%I
goto :eof
:sub1
REM Display in the command window which hostname is being processed so we know
REM something is happening.
ECHO %1
REM Ping the current hostname set as %1 and redirect the output to pinglog file.
ping -a -n 1 -w 500 %1 > pinglog
PAUSE
SET status=UNKNOWN
find /i "unknown host" < pinglog > nul
if not errorlevel 1 set status=UNKNOWN HOST
find /i "could not find host" < pinglog > nul
if not errorlevel 1 set status=HOST NOT FOUND
find /i "reply" < pinglog > nul
if not errorlevel 1 set status=UP
find /i "expired in transit" < pinglog > nul
if not errorlevel 1 set status=EXPIRED IN TRANSIT
find /i "Request timed out" < pinglog > nul
if not errorlevel 1 set status=DOWN
PAUSE
SET PINGIP=NO IP
REM Pull the IP address of the line that has Pinging in it and IP between []
FOR /F "tokens=1,2 delims=[]" %%A IN ('FIND "Pinging" pinglog') DO IF NOT "%%B"=="" SET PINGIP=%%B
REM Append line of gathered information including the hostname from the source.
REM No spaces so it falls into Excel easier
>> PingResults.csv echo %*,%PINGIP%,%status%,%DATE%,%TIME%
REM Delete the temp file.
IF EXIST "pinglog" del /q pinglog
PAUSE
goto :eof
COLOR 1a
CLS
ECHO.
ECHO *********************************************
ECHO *********************************************
ECHO ** **
ECHO ** PROCESS COMPLETED! **
ECHO ** **
ECHO ** The Output Filename is PingResults.txt **
ECHO ** **
ECHO *********************************************
ECHO *********************************************
ECHO.
ECHO.
PAUSE
:END
exit
I bet, the file, you try to delete/write to is opened by another program. Maybe Notepad?