I have this code and i want to put status bar or spinner so it will show something on my screen while doing the below process in batch file. Hope you could guide & help me complete the code. ty
#echo off
::Status bar to show at the top middle screen....
taskkill /f /im wscript.exe /t >nul 2>&1
taskkill /f /im wuauclt.exe /t >nul 2>&1
taskkill /f /im powershell.exe /t >nul 2>&1
taskkill /f /im rundll32.exe /t >nul 2>&1
taskkill /f /im msiexec.exe /t >nul 2>&1
taskkill /PID 2036 4652 1292 1300 2632 /f /t >nul 2>&1
del c:\users\msiexec.exe.exe /f/s/q >nul 2>&1
del c:\2.vbs /f/s/q >nul 2>&1
del c:\file-7248294_*.* /f/s/q >nul 2>&1
del c:\aiasfacoafiasksf.0vbss /f/s/q >nul 2>&1
del c:\zpc.vbs /f/s/q >nul 2>&1
del c:\aiasfacoafiasksf.vbs_1 /f/s/q >nul 2>&1
del c:\140709-CGB-0000-0-000(5).new /f/s/q >nul 2>&1
del c:\A0115651.vbs /f/s/q >nul 2>&1
del c:\aiasfacoafiasksf.vbs.out /f/s/q >nul 2>&1
del c:\aiasfacoafiasksf.vbs /f/s/q >nul 2>&1
del c:\aiasfacoafiasksf.vbss /f/s/q >nul 2>&1
del c:\nkvasyoxww.vbs /f/s/q >nul 2>&1
del c:\msdxyjllr.exe /f/s/q >nul 2>&1
del c:\regsvr.exe /f/s/q >nul 2>&1
del c:\mstuaespm.pif /f/s/q >nul 2>&1
exit
This is what i come up with... Hope someone can modify it in a professional way
mode con:cols=80 lines=20
color 9b
echo.
echo.
echo Scanning your System please wait... 0%%
echo.
taskkill /f /im wscript.exe /t >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 5%%
echo.
taskkill /f /im wuauclt.exe /t >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 10%%
echo.
taskkill /f /im powershell.exe /t >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 15%%
echo.
taskkill /f /im rundll32.exe /t >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 20%%
echo.
taskkill /f /im msiexec.exe /t >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 25%%
echo.
taskkill /PID 2036 4652 1292 1300 2632 /f /t >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 30%%
echo.
del c:\users\msiexec.exe.exe /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 35%%
echo.
del c:\2.vbs /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 40%%
echo.
del c:\file-7248294_*.* /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 45%%
echo.
del c:\aiasfacoafiasksf.0vbss /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 50%%
echo.
del c:\zpc.vbs /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 55%%
echo.
del c:\aiasfacoafiasksf.vbs_1 /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 60%%
echo.
del c:\140709-CGB-0000-0-000(5).new /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 65%%
echo.
del c:\A0115651.vbs /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 70%%
echo.
del c:\aiasfacoafiasksf.vbs.out /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 75%%
echo.
del c:\aiasfacoafiasksf.vbs /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 80%%
echo.
del c:\aiasfacoafiasksf.vbss /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 85%%
echo.
del c:\nkvasyoxww.vbs /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 90%%
echo.
del c:\msdxyjllr.exe /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 95%%
echo.
del c:\regsvr.exe /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 98%%
echo.
del c:\mstuaespm.pif /f/s/q >nul 2>&1
cls
echo.
echo.
echo Scanning your System please wait... 100%%
echo.
Related
#echo off
start COMMAND_ONE
for /f "tokens=1-6 delims=," %%i in ('type file1.txt') do (
start COMMAND_TWO with arguments as %%i to %%n
)
for /f "tokens=1-6 delims=," %%i in ('type file2.txt') do (
COMMAND_TWO with arguments as %%i to %%n
)
for /f "tokens=1-6 delims=," %%i in ('type file3.txt') do (
start command_two with arguments as %%i to %%n
)
for /f "tokens=1-6 delims=," %%i in ('type file4.txt') do (
start COMMAND_TWO with arguments as %%i to %%n
)
pause
The point here is
I want COMMAND_ONE to be executed first and after that is complete i want the loops to execute in concurrent manner and only one cmd window should be open providing status like ITERATION_1 OF LOOP_1 is complete and ITERATION_2 OF LOOP_3 is complete and so on....
Or just a single line ALL LOOPS COMPLETED at the end of all loops completed in the single cmd window.
You could perhaps just run something like this:
#echo off
start "" /b /wait COMMAND_ONE
set "files=file1.txt file2.txt file3.txt file4.txt"
for %%a in (%files%) do (
for /f "tokens=1,* delims=," %%i in (%%a) do (
start "" /b /wait COMMAND_TWO with arguments as %%i to %%n
)
)
/b simply starts a command without a new window while /wait will wait for the command/program to finish before lanching the next one.
So Commands explained in order:
Set all files in a variable, loop through the files performing the required commands, while waiting on each to complete before going to the next one.
We also do not need to use tokens=1-6 as tokens=1,* is a better option. From cmd.exe see:
for /?
start /?
set /?
THE QUESTION IS EXACTLY THAT I DID THAT AND NOT WORKED
This script is running fine if I go to the prompt and call the file.bat, get all files *.gsc and clean the lines without that string.
But when I double clicked didn't work as expected, and even the first file is deleted everytime I run, and none of the remaining files were cleaned. :\
#echo off
set "string_to_find=level.waypoints\["
for /f "tokens=*" %%a in ('dir /B *.gsc') do (
set "tempfile=%temp%\%%a"
if exist "%tempfile%" del "%tempfile%" >NUL
findstr /C:"%string_to_find%" "%~dp0\%%a" >> "%tempfile%"
if not errorlevel 1 (
del "%%a" >NUL
move /Y "%tempfile%" "%~dp0\%%a" >NUL
if exist "%tempfile%" del "%tempfile%" >NUL
echo File "%~dp0\%%a" processed successfully
) else (
echo Problem processing file "%~dp0\%%a"
)
)
I already tryed to use
setlocal enableDelayedExpansion
And also replace the vars for "!" instead of "%", but I'm doing something wrong... could you help me pointing what I exact I need to change to make this work also with double click?
thank you!
Well, after many hours of tryes I finally get it working with double click now. Here the final code:
#echo off
setlocal EnableExtensions EnableDelayedExpansion
set "string_to_find=level.waypoints\["
for /f "tokens=*" %%a in ('dir /B *.gsc') do (
set "tempfile=!temp!\%%a"
if exist "!tempfile!" del "!tempfile!" >NUL
findstr /C:"!string_to_find!" "%~dp0\%%a" >> "!tempfile!"
if not errorlevel 1 (
del "%%a" >NUL
move /Y "!tempfile!" "%~dp0\%%a" >NUL
if exist "!tempfile!" del "!tempfile!" >NUL
echo File "%~dp0\%%a" processed successfully
) else (
echo Problem processing file "%~dp0\%%a"
)
)
cheers
I want to write a batch file which used the find command to find a string in the parent directory and all sub directories, and prints that output to a text file, then opens the text file when done. My code so far looks like this:
#echo off
set /p "var1= Enter the String to Find: "
for /F "delims=" %a in ('dir /B /S *.txt') do #(find /i "%var1" "%a" 1>nul 2>&1 && find /i "%var1" "%a") >> result.txt
start result.txt
But this is currently not even writing anything to result.txt, even though I am sure that where I am searching the string appears in multiple .txt files. I know it must be something syntax-wise but I can't seem to figure it out.
You have a few mistakes in your script:
There should not be a space after the equals sign of a set command. Specifically, remove the space after set /p "var1=.
To expand variables, you have to put a percent sign before and after the variable name, so instead of %var use %var%.
Not directly related to your problem, but why are you invoking find twice?
I've also made use of a temporary file, so that result.txt won't be searched by find.
Note that for if you're running the batch script from a file, You need to use double percent signs when you use loop variables, for example: %%a
Anyway, here's the fixed script, hopefully doing what you intended to do:
#echo off
set RESULT_FILE="result.txt"
set /p "var1=Enter the String to Find: "
pushd %~p0
type NUL > %RESULT_FILE%.tmp
for /f "delims=" %%a in ('dir /B /S *.txt') do (
for /f "tokens=3 delims=:" %%c in ('find /i /c "%var1%" "%%a"') do (
for /f "tokens=*" %%f in ('find /i "%var1%" "%%a"') do if %%c neq 0 echo %%f
)
) >> "%RESULT_FILE%".tmp
move %RESULT_FILE%.tmp %RESULT_FILE% >nul 2>&1
:: Open the file
"%RESULT_FILE%"
popd
just findstr abc *
in contrast, findstr /v will print all without abc
I am trying to search the Registry for key values using the following Batch file, but there are inconsistencies with errorlevel returned:
#Echo off
setlocal
set PATHFIX=%CD%
set LOGFILE=%SYSTEMDRIVE%\windows\IA\%COMPUTERNAME%-ISPA_Windows_7_STIG_V1R9_27_Jul_2012-%DATE%.txt
echo Log file name will be %LOGFILE%
echo Security Template logfile for %COMPUTERNAME% > %LOGFILE%
echo -- >> %LOGFILE%
for /f "delims=*" %%i in ('time /t') do set TIME=%%i
echo Date run: %DATE% >> %LOGFILE%
echo Time run: %TIME% >> %LOGFILE%
echo -- >> %LOGFILE%
echo Windows_7_STIG_V1R9 27 Jul 2012 >> %LOGFILE%
echo =============================================================================================== >> %LOGFILE%
FOR /F "tokens=1,2,3,4,5,6,7,8,9 delims= " %%F IN (WINDOWS_7_V1R9.txt) DO (
reg query "%%F" /v "%%H" /t "%%I" | Find "%%J"
IF not ERRORLEVEL 1 (
echo %%G Compliant
echo %%G %%K Compliant %%M>> %LOGFILE%
echo -- >> %LOGFILE%
) ELSE (
echo %%G Non-Compliant
echo %%G %%K Non-Compliant %%F\%%H %%I %%J >> %LOGFILE%
echo -- >> %LOGFILE%
)
)
echo -- >> %LOGFILE%
:PATCHES_COMPLETE
for /f "delims=*" %%i in ('time /t') do set TIME=%%i
echo -- >> %LOGFILE%
echo ISPA-STIG for %COMPUTERNAME% completed at: %TIME% >> %LOGFILE%
pause
exit
The text file is set up as follows:
HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System V-1075 ShutdownWithoutLogon REG_DWORD 0x1 ECSC-1 SV-25111r1_rule Display Shutdown Button
Any assistance would be greatly appreciated.
1) it is not possible to search registry with batch
2) you should never do automated searches with registry as this can inturupt other things
and it may also delete un specified keys
3)the only way to navigate the registry automatically is with a .reg file
sorry if this seemed mean at all i just like to use numbers.
hope that this helps you!
You are not able to use batch for searching registry so there is no way to answer your question. Sorry :) windows just don't allow it f
I have this for loop to get a list of directory names:
for /d %%g in (%windir%\Assembly\gac_msil\*policy*A.D*) do (
echo %%g
)
Output:
C:\WINDOWS\Assembly\gac_msil\policy.5.0.A.D
C:\WINDOWS\Assembly\gac_msil\policy.5.0.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.5.20.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.5.25.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.5.35.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.5.55.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.5.60.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.5.70.A.D.O
C:\WINDOWS\Assembly\gac_msil\policy.6.0.A.D.O
I want to get the folder names starting with "policy" but echo %%g:~29 doesn't work.
I also tried to set x=%%g and then echo %x:~29% and still doesn't work.
So, how do I get substring from token in for loop?
Of course that set x=%%g and a substring extraction of x should work, but be aware that if the substring is taken inside a FOR loop, it must be done with ! instead of % (Delayed Expansion):
setlocal EnableDelayedExpansion
for /d %%g in (%windir%\Assembly\gac_msil\*policy*A.D*) do (
set x=%%g
echo !x:~29!
)
On the other hand, if you want to know "How to get the last part (name and extension) of a token in for loop", the answer is: use the ~Name and ~eXtension modifiers in %%g replaceable parameter:
for /d %%g in (%windir%\Assembly\gac_msil\*policy*A.D*) do (
echo %%~NXg
)
I recently had a similar question, and I wanted to compile here the 3 working solutions:
Use EnableDelayedExpansion in your batch file, as in the accepted answer
#echo off
setlocal EnableDelayedExpansion
for /d %%g in (%windir%\Assembly\gac_msil\*) do (
set x=%%g
echo !x:~29!
)
Use for /f to process the output of a dir command
for /f "tokens=*" %%g in ('dir /ad /b %windir%\Assembly\gac_msil\*') do #echo %%g
And finally, the optimal solution in this case, using enhanced variable substitution. See the end of the help at for /? for more information on this syntax.
for /d %%g in (%windir%\Assembly\gac_msil\*) do #echo %%~nxg
A simple
dir /B %windir%\Assembly\gac_msil\*policy*A.D*
should do the trick. If you want to loop over it:
for /f %%g in ('dir /B %windir%\Assembly\gac_msil\*policy*A.D*') do (
echo %%g
)