|
Answer» Hi all, I have a Batch file to ping for all hostnames inside my domain by brings these hostnames from an external text file (hosts.txt) and it works properly while using it as a bat file, but after converting this file to an executable file (exe) and try to use it, its display an error message contain that (The system cannot find the file "hosts.txt" ) why does this happen? And how can fix this issue? Here is the mentioned code:
Code: [Select]echo off title Ping Batch using "External Text File" setlocal enableextensions enabledelayedexpansion color 0a Rem mode 125,35 mode con:cols=105 lines=30 TIMEOUT /T 1 /NOBREAK >nul ECHO. ====================================================================================================== && ping -n 1 localhost >nul ECHO. ^|^| ------====^<({ Welcome to AMIN Muhammad Batches })^>====------ ^| ---===^<({ Created By :- })^>===--- ^|^| && ping -n 1 localhost >nul ECHO. ^|====================================================================================================^| && ping -n 1 localhost >nul ECHO. ^| - This tool will help you wherever you are, ^| ^| && ping -n 1 localhost >nul ECHO. ^| just you must be an administrator on your domain. ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| - Ping Package Menu:- ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| - Now You can Ping Bulk Machines, just insert the text file ^| ^| && ping -n 1 localhost >nul ECHO. ^| (hosts.txt)that contains all hosts you need to ping it and ^| Compatible with Windows 7 and later^| && ping -n 1 localhost >nul ECHO. ^| be sure that the file located in the same directory. ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| (Write related choice to do what you want) ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ^| ^| ^| && ping -n 1 localhost >nul ECHO. ====================================================================================================== && ping -n 1 localhost >nul ECHO. TIMEOUT /T 1 /NOBREAK >nul echo. You are about to Ping the whole machines in your file , Are you sure? TIMEOUT /T 1 /NOBREAK >nul echo. echo. You have 30 Seconds to choose Or the program will terminate choice /c YN /t 30 /d n /m " PRESS 'Y' to Continue or press 'N' to Cancel "
If %ErrorLevel%==1 GoTo y If %ErrorLevel%==2 GoTo n
:y cls TIMEOUT /T 1 /NOBREAK >nul echo This Operation has been Confirmed. TIMEOUT /T 1 /NOBREAK >nul echo Now it will start after the below timeout. TIMEOUT /T 5 /NOBREAK cls
set /a "countOn=0" set /a "countOff=0"
for /f %%i in (hosts.txt) do ( set SERVER_ADDRESS_I=UNRESOLVED_IP set SERVER_ADDRESS_L=UNRESOLVED_IP SET bHOSTUP=0 ping -n 1 %%i -w 2000 |find "TTL=" > NUL && SET bHOSTUP=1 IF !bHOSTUP! equ 1 ( set g=%%i CALL :HOSTUP %%i ) else ( set g=%%i CALL :HOSTDOWN %%i ) )
pause GOTO EOF
:n cls color fc TIMEOUT /T 1 /NOBREAK >nul echo. This Operation has been canceled TIMEOUT /T 3 /NOBREAK GOTO EOF
:HOSTUP Rem add 1 number to countOn variable for each online machine set /a "countOn+=1"
for /f "tokens=1,2,3" %%x in ('ping -a -n 1 %g% ^&^& echo SERVER_IS_UP') do ( if %%x==Pinging set SERVER_ADDRESS_L=%%y if %%x==Pinging set SERVER_ADDRESS_I=%%z )
Echo %g% : %SERVER_ADDRESS_I% : Is Pingable
set /a "rand+=5" if %rand% geq 181 set /a "rand=0" echo.[%g% : %SERVER_ADDRESS_I% : is Online and Pingable]>>"Online Workstations Result for Ping.txt" GOTO EOF
:HOSTDOWN Rem add 1 number to countOff variable for each offline machine set /a "countOff+=1"
for /f "tokens=1,2,3" %%x in ('ping -a -n 1 %g% ^&^& echo SERVER_IS_UP') do ( if %%x==Pinging set SERVER_ADDRESS_L=%%y if %%x==Pinging set SERVER_ADDRESS_I=%%z )
Echo %g% : %SERVER_ADDRESS_I% : Is Offline or Not Exist echo.[%g% : %SERVER_ADDRESS_I% : Is Offline or Not Exist]>>"Offline Workstations Result for Ping.txt" GOTO EOF
:EOF exit /B
and You must have another text file named "hosts.txt" contain at all hostnames separated by Enter button and this file located in the same directoryI converted your file using Bat To Exe Converter v3.2 and using an empty hosts.txt ran your script with no errors. It may have to do with the converter you are using. In line 54 the hosts files is referenced with no path, so the current directory is used, but the converter may have either changed it or put it in a different variable.
Try inserting:
Code: [Select]echo %cd% pause prior to line 54, so you can check where the hosts.txt file is actually being SEARCHED for.
Also, why the secrecy? Your batch script is 6K, but the exe file is 96K.
BTW, I used the converter from here: https://www.softpedia.com/get/System/File-Management/Batch-To-Exe-Converter.shtmlThe last line is your ffmpeg command, so any parameters you want to feed to ffmpeg would go there.
So for instance, if you're working with H.265, you could remove the -c:v copy and replace it with
-vcodec libx265 -crf 28 This is just one example, mp4 containers can have any number of codecs...
Effectively, you can think of all of the lines before the last line as figuring out the parameters to feed your ffmpeg command.
Quote from: Cook869 on March 27, 2021, 06:06:10 AM The last line is your ffmpeg command, so any parameters you want to feed to ffmpeg would go there.
So for instance, if you're working with H.265, you could remove the -c:v copy and replace it with
-vcodec libx265 -crf 28 This is just one example, mp4 containers can have any number of codecs...
Effectively, you can think of all of the lines before the last line as figuring out the parameters to feed your ffmpeg command.
Your comments have nothing to do with this thread at all. Did you mean to post this in a different thread?
Quote from: Abo-Zead on March 23, 2021, 09:26:10 AMYou must have another text file named "hosts.txt" contain at all hostnames separated by Enter button
How about we call it what it is. A carriage return and line feed. Or hex 0D 0A. Or for you really big nerds: 0000110100001010
Quote from: Sidewinder on March 25, 2021, 01:13:52 PMI converted your file using Bat To Exe Converter v3.2 and using an empty hosts.txt ran your script with no errors. It may have to do with the converter you are using. In line 54 the hosts files is referenced with no path, so the current directory is used, but the converter may have either changed it or put it in a different variable.
Try inserting:
Code: [Select]echo %cd% pause prior to line 54, so you can check where the hosts.txt file is actually being searched for.
Also, why the secrecy? Your batch script is 6K, but the exe file is 96K.
BTW, I used the converter from here: https://www.softpedia.com/get/System/File-Management/Batch-To-Exe-Converter.shtml
Thanks, Sidewinder for your help and no secrecy in my question it's just simple bat file
|