A friend of mine received some "tech support" from a questionable source and they left a batch file on his computer entitled "Junk Remover". I am suspicious of the batch file but I have no idea what the batch is doing. I was hoping someone could shine some light on what is going on when this batch is run.
#echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
exit
Thanks in advance for anyone taking a look and help would be appreciated.
Related
I have some code here that is being used to clear the event viewers on a few pcs. Currently I have to run this batch file with administrator access. Could someone help me in trying to modify it to just run normally.
Thanks
Here is the code
#echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
exit
Ok, I have this batch file, and I would like to detect if the user's input includes a certain character, like ..
Here is what I have so far...
IF /I %option%== ATTRIB +h
(I would like it to detect if there is a . pressed)
I would like the .bat to detect If there is something other than Attrib +h pressed, like a ., for a file extension. So that if there was a file given, I would not ask for a file name again, because it wouldn't run properly!
Here is a part of the code, for Magoo.
#echo off
title iControl
color 80
:home
cls
echo iControl: Logan Murphy Version 1.5.7
echo Copyright 2014 Logan Murphy. All rights reserved.
GOTO jiki
:jiki
title iHelp
echo.
set /p "SSL=%USERNAME%>Execute>"
echo %SSL%"|find "." >nul
cls
if errorlevel 1 (echo notfound) else (ATTRIB +h)
rem IMPLEMENTED IT HERE!
rem Here we go
rem need to fix execution
IF /I %SSL%==attrib goto attrib
IF /I %SSL%==pause goto pause
IF /I %SSL%==backup goto backup
Edit: Ok, the answers from magoo and john really helped, but if i wanted this to detect a folder name, as well as a file name, what would i change?
Edit: Ok Magoo, testing it now.
Edit: That doesnt really work well, as I am trying to find out if the variable INCLUDES a certain character, not if the whole variable is = to a valid file/folder name, but nice try. Will mess around with it a bit... Thanks for your time Magoo, I appreciate it:)
Edit: I think I worked it out! Thanks everyone who helped me!
Here is my new code...
#echo off
title iControl
color 80
:home
cls
echo iControl: Logan Murphy Version 1.5.7
echo Copyright 2014 Logan Murphy. All rights reserved.
GOTO jiki
:jiki
title iHelp
echo.
set /p "SSL=%USERNAME%>Execute>"
%SSL%
cls
goto Seconds
:Seconds
IF /I %SSL%==attrib goto attrib
IF /I %SSL%==attrib +h goto attrib+-
IF /I %SSL%==attrib -h goto attrib+-
IF /I %SSL%==attrib +r goto attrib+-
IF /I %SSL%==attrib -r goto attrib+-
The general formula would be
echo "%var%"|find "characterorstringrequired" >nul
if errorlevel 1 (echo notfound) else (echo found)
So, for your instance,
echo "%option%"|find "i" >nul
if errorlevel 1 (echo notfound) else (ATTRIB +h)
Beyond which, I have to be as vague as your question, I'm afraid...
After seeing part-code...
echo "%SSL%"|find "." >nul
cls
if errorlevel 1 (echo notfound) else (ATTRIB +h)
I'm not sure whether cls affects errorlevel. The test should be executed directly after the command that establishes errorlevel - which is the echo %SSL... line.
echo "%SSL%"|find "." >nul
if errorlevel 1 (echo notfound) else (ATTRIB +h)
Serious damage can be done by cmd if the commands are not understood. The attrib command requires a target, so it should be
... else (attrib +h something)
to set something to hidden.
beyond that - it's not a good idea to use cmd keywords like attrib, pause and backup as labels. It can cause damage in the case of a tyop.
The benefit of sying what you want to do instead of how you want to do whatever-it-is.
To test for a file's existence, try
if exist "%SSL%" (echo "%SSL%" exists) else (echo "%SSL%" is not there)
where echo can be any legitimate (series of) command(s).
What about something like this for all special chars ?
#echo off
:_Start
set /p "FID="
set FID="%FID:"=%"
setlocal EnableDelayedExpansion
for %%I in (^| ^& ^< ^> ^^ ^( ^) ' ` ^%% ^") do set FID=!FID:%%I=!
setlocal DisableDelayedExpansion
set FID="%FID:!=%"
endlocal&set FID=%FID:~1,-1%
:_Back
set _Flag1=
for /f "tokens=1* delims=~=*;,?-+\/.##${}[]: " %%J in ('echo !FID!') do (
set FID=%%J%%K
set _Flag1=%%J
set _Flag2=%%K
)
if NOT "%_Flag2%"=="" goto :_Back
if NOT defined _Flag1 goto :_Start
endlocal&set FID=%FID%
echo %FID%
pause
The VBA command for finding a character in a string is INSTR so if you are looking for a . for example then in VBA could could use INSTR. There are two ways to do what you want:
Write a QBASIC or VBscript version of INSTR and then call that from a BATCH script
Write a batch script that does INSTR.
If you are interested in the second one look at http://www.dostips.com/forum/viewtopic.php?f=3&t=1986
It isn't as efficied as the first one would be because INSTR is pretty much a one liner in VBScript and the batch version does a character by character comparison, but if you are looking for a batch only solution that may do what you want.
Have looked about the web but cant find anything that can help. I am trying to make a page that can delete something of a page. Have managed to make a search that can tell you if a word is on the .txt file. How would I put it into this?
cls
set /p SEARCH= Please enter what you want to look for?
for /f "Delims=" %%a in (test.txt) do (
set FIND=%%a
)
if %SEARCHS%==%FIND% goto FLIGHT HAS ARRIVED
echo We were not able to find %SEARCH%
pause
goto start
Does anybody know what I should do?
Thanks,
Alex
type file|find "string in lines to remove" /i /v >newfile
might help.
set /p reg=text:for /f "delims=" %%i in (file.txt) do if %%a'==%reg%' goto found
I can't tell what you want to do though so if this doesn't help please elaborate.
try this:
#ECHO OFF &SETLOCAL
set /p "SEARCH= Please enter what you want to look for? "
for /f "Delims=" %%a in ('find "%SEARCH%" test.txt') do set "FOUND=%%a"
if DEFINED FOUND goto FLIGHT_HAS_ARRIVED
echo We were not able to find %SEARCH%
pause
goto start
:FLIGHT_HAS_ARRIVED
ECHO %SEARCH% found: %FOUND%
goto:eof
You shouldn't use cmd command names for variable names (%FIND%).
Jump labels do not work as expected, if it contain spaces: FLIGHT HAS ARRIVED
Ok, I am trying to make a batch file to generate a series of files and folders, but can't find on how to do it.
My Idea:
FOR /f "Tokens=* delims=" %%I IN (export2.csv) DO call:create %%I GOTO:EOF
:create ECHO 1 >>%~pd0%1
But it didn't work at all.
Since I have no idea how your data file looks like it's hard to give good advice here, but your code could be cleaned up a bit:
set "filepath=%~dp0"
for /f "tokens=* delims=" %%I in (export2.csv) do call :create "%%I"
rem This is needed to avoid stepping into the subroutine again
goto :eof
:create
rem This will create an empty file instead of one that contains a single line with 1
copy nul "%filepath%%~1"
goto :eof
This won't create any directories, though. You can create those with md.
Figured it out a little bit ago and here is what I ended up with. It will generate both the path and create an empty file with the name of the file listed in the masterlist.csv.
Source Code
#ECHO OFF
CHDIR "%~dp0"
SET Count=0
ECHO/ Generating Necessary File, please Wait...
FOR /F %%A IN (Masterlist.csv) DO CALL:MKDIR %%A
EXIT /B
:MKDIR
SET /A Count+=1
SET "Path=%~dp1"
SET "File=%~nx1"
IF NOT EXIST "%Path%" MKDIR "%Path%
IF NOT EXIST "%Path%" CALL:ERROR "Path"
IF NOT EXIST "%Path%\%File%" ECHO/ >>"%Path%\%File%"
IF NOT EXIST "%Path%\%File%" CALL:ERROR
EXIT /B
:ERROR
IF NOT EXIST "Errorlog.csv" ECHO Error, Line Count>>Errorlog.csv
ECHO %~1, Line %Count%>>Errorlog.csv
A few example lines from Masterlist.csv
2006\MS06-003\Office2000\office2000-kb892842-fullfile-enu.exe
2006\MS06-003\Office2003\office2003-kb892843-fullfile-enu.exe
2006\MS06-003\Office2003\WinSec-MS06-003-009-P44333-outlook2003-kb892843-fullfile-enu.exe
2006\MS06-003\OfficeXP\officexp-kb892841-fullfile-enu.exe
2006\MS06-006\WindowsMedia-KB911564-x86-ENU.exe
2006\MS06-007\2003\WindowsServer2003-KB913446-x86-ENU.exe
2006\MS06-007\XP\WindowsXP-KB913446-x86-ENU.exe
2006\MS06-012\2003\office2003-KB905756-FullFile-ENU.exe
2006\MS06-015\2000\Windows2000-KB908531-x86-ENU.EXE
2006\MS06-015\2003\WindowsServer2003-KB908531-x86-ENU.exe
In a batch file I want to see if %1 is in a set.
E.g., as an alternative to
if %1 equ /? goto help
if /I %1 equ -? goto help
if /I %1 equ /help goto help
etc
It seems like it should be simple, but I can't make it work. I've tried with and without FOR loops and search:string.
#echo off
setlocal enabledelayedexpansion
set "helpoptions=#/?#-?#/help#"
if not "!helpoptions:#%~1#=!"=="%helpoptions%" goto help
goto :eof
:help
echo Help
would be an option, albeit not a very pretty one.