2016-11-14 12 views
1

私は複数の文字列を見つける必要がありますが、文字列はバッチ自体にあるために旗を探します。シークレットの文字列とそのフラグを含むバッチを検索します。これをどうやって防ぐのですか?FindStrで何かが表示されないようにするにはどうしたらいいですか?


編集:これは現在のコードのスニペットです。基本的にはテキストファイルを開いて、良いですあまりにもそれと他のもので、このバッチファイルを示していますが、私は旗にはない、このバッチファイルを、それを必要とします。

findstr /i /s /m "Obligatory" *.* > str-unfixed.txt 
if %errorlevel%==0 (
Call :TypeWriter "Obligatory Strings Found." 
) else (
Call :TypeWriter "No Obligatory Strings Found." 
) 
start "" "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" 

これは単なるスニペットです。


Edit2:編集のおかげで、Mofiはコンソールで空白になり、完了しません。 完全なスクリプト。さあ。

@echo off 
goto Next 
::************************************************************* 
:TypeWriter 
echo(
(
echo strText=wscript.arguments(0^) 
echo intTextLen = Len(strText^) 
echo intPause = 30 
echo For x = 1 to intTextLen 
echo  strTempText = Mid(strText,x,1^) 
echo  WScript.StdOut.Write strTempText 
echo  WScript.Sleep intPause 
echo Next 
)>%tmp%\%~n0.vbs 
@cscript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1" 
echo(
exit /b 
::************************************************************** 
:Next 
@echo off 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 
%SystemRoot%\System32\findstr.exe /i /s /m "Vape" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >"%OutputFile%" 
for %%I in ("%OutputFile%") do if %%~zI == 0 goto VapeNoFileFound 
for %%I in ("%OutputFile%") do if %%~zI == 1 goto VapeFileFound 
:VapeFileFound 
Call :TypeWriter "Vape Strings Found." 
goto Kurium 
:VapeNoFileFound 
Call :TypeWriter "No Vape Strings Found." 
goto Kurium 

:Kurium 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 
%SystemRoot%\System32\findstr.exe /i /s /m "Kurium" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%" 
for %%I in ("%OutputFile%") do if %%~zI == 0 goto KuriumNoFileFound 
for %%I in ("%OutputFile%") do if %%~zI == 1 goto KuriumFileFound 
:KuriumFileFound 
Call :TypeWriter "Kurium Strings Found." 
goto Spook 
:KuriumNoFileFound 
Call :TypeWriter "No Kurium Strings Found." 
goto Spook 

:Spook 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 
%SystemRoot%\System32\findstr.exe /i /s /m "Spook" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%" 
for %%I in ("%OutputFile%") do if %%~zI == 0 goto SpookNoFileFound 
for %%I in ("%OutputFile%") do if %%~zI == 1 goto SpookFileFound 
:SpookFileFound 
Call :TypeWriter "Spook Strings Found." 
goto Aimassist 
:SpookNoFileFound 
Call :TypeWriter "No Spook Strings Found." 
goto Aimassist 

:Aimassist 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 
%SystemRoot%\System32\findstr.exe /i /s /m "Aimassist" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%" 
for %%I in ("%OutputFile%") do if %%~zI == 0 goto AANoFileFound 
for %%I in ("%OutputFile%") do if %%~zI == 1 goto AAFileFound 
:AAFileFound 
Call :TypeWriter "Aim Assist Strings Found." 
goto Triggerbot 
:AANoFileFound 
Call :TypeWriter "No Aim Assist Strings Found." 
goto Triggerbot 

:Triggerbot 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 
%SystemRoot%\System32\findstr.exe /i /s /m "Triggerbot" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >>"%OutputFile%" 
for %%I in ("%OutputFile%") do if %%~zI == 0 goto TRNoFileFound 
for %%I in ("%OutputFile%") do if %%~zI == 1 goto TRFileFound 
cscript //nologo "C:\Users\%USERNAME%\Desktop\dedup.vbs" < "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" > "C:\Users\%USERNAME%\Desktop\str-fixed.txt" 
del /s /q "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" > nul 
:TRFileFound 
Call :TypeWriter "Triggerbot Strings Found." 
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt" 
:TRNoFileFound 
Call :TypeWriter "No Triggerbot Strings Found." 
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt" 

pause > nul 
::************************************************ 

そして、あなたはdedup.vbsが必要な場合:ありがとうMofi:


EDIT3

Set Inp = WScript.Stdin 
Set Outp = Wscript.Stdout 
Set Dict = CreateObject("Scripting.Dictionary") 
Do Until Inp.AtEndOfStream 
    On Error Resume Next 
    Line=Inp.readline 
    Dict.Add Line, "" 
Loop 
For Each thing in Dict.Keys() 
    Outp.writeline thing 
Next 

私の問題:CMDウィンドウに表示するテキストドキュメント内の項目を取得する必要があります。

スクリプト:

@echo off 
goto Next 
::************************************************************* 
:TypeWriter 
echo(
(
echo strText=wscript.arguments(0^) 
echo intTextLen = Len(strText^) 
echo intPause = 30 
echo For x = 1 to intTextLen 
echo  strTempText = Mid(strText,x,1^) 
echo  WScript.StdOut.Write strTempText 
echo  WScript.Sleep intPause 
echo Next 
)>%tmp%\%~n0.vbs 
@cscript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1" 
echo(
exit /b 
::************************************************************** 
:Next 
@echo off 
findstr /i /s /m /C:"Vape" /C:"Kurium" /C:"Spook" /C:"Aimassist" /C:"Triggerbot" /C:"Smoothaim" *.* > str-unfixed.txt 
cscript //nologo "C:\Users\%USERNAME%\Desktop\dedup.vbs" < "C:\Users\%USERNAME%\Desktop\str-unfixed.txt" > "C:\Users\%USERNAME%\Desktop\str-fixed.txt" 
if %errorlevel%==0 (
Call :TypeWriter "Blacklisted Strings Found." 
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt" 
) else (
Call :TypeWriter "No Blacklisted Strings Found." 
start "" "C:\Users\%USERNAME%\Desktop\str-fixed.txt" 
) 
pause > nul 
::************************************************ 
+0

あなたが求めていることは明確ではありません。あなたの現在のコードと明確な問題の声明を投稿してください。 [How to Ask](https://stackoverflow.com/help/how-to-ask)を参照してください。 –

+0

"バッチ内にあるためのフラグ"とはどういう意味ですか?出力と何が期待されているかを表示 –

+0

バッチファイルを含むディレクトリをスキャンしようとしているようですが、バッチファイル自体は除外しているようです。最も簡単な方法は、バッチを別のディレクトリに置くことです。 –

答えて

0

バッチファイルがこのコードを使用して、例えば除外することができる:

@echo off 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 
%SystemRoot%\System32\findstr.exe /I /M /S "Obligatory" *.* | %SystemRoot%\System32\findstr.exe /E /L /V /C:"%~nx0" >"%OutputFile%" 
for %%I in ("%OutputFile%") do if %%~zI == 0 goto NoFileFound 

call :TypeWriter "Obligatory strings found." 
start "" "%OutputFile%" 
set "OutputFile=" 
goto :EOF 

:NoFileFound 
del "%OutputFile%" 
set "OutputFile=" 
call :TypeWriter "No obligatory string found." 
goto :EOF 

:TypeWriter 
echo %~1 

FINDSTRの出力は、第2 FINDSTRで濾過されすべての行は、バッチファイルの名前で終わらない出力は、大文字と小文字を区別し、文字列リテラルとして検索しました。

コマンドを使用して、出力ファイルのファイルサイズを確認します。

出力ファイルは空のファイルですか?つまり、ファイルサイズは0バイトです。出力ファイルを削除して適切なメッセージを出力するバッチファイル自体を除いて、文字列Obligatoryは見つかりませんでした。

は、そうでない場合は、文字列が見つかったメッセージを印刷した後、出力ファイルは、ファイル拡張子.txtに関連付けられたアプリケーションで開かれます。

上記のバッチファイルは、サブディレクトリの全体ではなく、ドライブCの両方のシナリオについて試験した:それはCに終了するまでにはかなり時間がかかることがありますよう:. Cドライブ上のファイルの百何千もあります。全部でジブの数十は、ファイル名のパターンとして*.*を使用した場合、文字列を検索し、ドライブCのルートに開始すると:.


EDIT 1:上記のようにはるかに優れたソリューションは、バッチファイルにある検索文字列を避けている二つの部分

で検索した文字列を定義します。これは、文字列の環境変数を使用して、環境変数の値を2つのステップで見つけて定義することによって実行できます。

@echo off 
setlocal 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 

set "StringToFind=Obli" 
set "StringToFind=%StringToFind%gatory" 

%SystemRoot%\System32\findstr.exe /I /M /S "%StringToFind%" *.* >"%OutputFile%" 

if errorlevel 1 (
    del "%OutputFile%" 
    call :TypeWriter "No %StringToFind% strings found." 
) else (
    call :TypeWriter "%StringToFind% strings found." 
    start "" "%OutputFile%" 
) 

endlocal 
goto :EOF 

:TypeWriter 
echo %~1 

このバッチファイルもObligatoryを検索し、それがこの文字列だけObligatoryが含まれていません。


EDIT 2:ここでは

は、複数の文字列が途中でどこかエスケープ文字^で環境変数に割り当てられている見つけるためにもう一つの解決策である省略エスケープ文字で検索した文字列を定義します。バッチファイルを除外するために文字列を検索します。

^は、Windowsコマンドインタープリタによって、検索文字列を環境変数に割り当てるときに、二重引用符で囲まれた文字列内に見つからないものとして削除されます。このソリューションは、末尾の空白(s)は、環境変数に割り当てられるよう

set SearchX=S^earch String 

行が1以上の末尾のスペース/タブを持っていないことが必要ですのでご注意ください。検索文字列の一部として表示されている行の末尾に表示されていない空白または水平のタブを使用して、検索が期待通りに機能しなくなりました。のファイル名を出力します。FINDSTRは、6つの検索文字列のうちの1つをコンソールウィンドウに表示し、次にそのファイル名を出力テキストファイルにリダイレクトします。使用するコマンドを理解し、どのように彼らは、コマンドプロンプトウィンドウを開き、そこに次のコマンドを実行し、完全にページが非常に慎重に、各コマンドのために表示されているすべてのヘルプを読んで、仕事のため

@echo off 
setlocal EnableExtensions 
set "OutputFile=%USERPROFILE%\Desktop\str-unfixed.txt" 

rem Define all search strings with omitted escape character. 
set Search1=V^ape 
set Search2=K^urium 
set Search3=S^pook 
set Search4=A^imassist 
set Search5=T^riggerbot 
set Search6=S^moothaim 

rem Delete the output file from a previous run if existing at all. 
del "%OutputFile%" 2>nul 

for /F "delims=" %%I in ('%SystemRoot%\System32\findstr.exe /I /M /S /C:"%Search1%" /C:"%Search2%" /C:"%Search3%" /C:"%Search4%" /C:"%Search5%" /C:"%Search6%" *') do (
    echo %%I 
    echo %%I>>"%OutputFile%" 
) 

if exist "%OutputFile%" (
    call :TypeWriter "Obligatory strings found." 
    start "" "%OutputFile%" 
) else (
    call :TypeWriter "No obligatory string found." 
) 
endlocal 
goto :EOF 

:TypeWriter 
echo %~1 

  • call /?
  • del /?
  • echo /?
  • endlocal /?
  • findstr /?
  • for /?
  • goto /?

  • start /?
  • setlocal /?
  • は、Microsoftのサポート記事Testing for a Specific Error Level in Batch FilesとMicrosoft TechNetの記事Using command redirection operatorsを参照してください。

  • 0

    スクリプト名をもう一度チェックして結果をパイプするだけです。

    が、これでfindstr /i /s /m "Obligatory" *.* > str-unfixed.txtをあなたの最初の行を置き換え:ドライブは、特定の検索用語を探して:

    findstr/ism "Obligatory" *.*|findstr/ixvc:"%~nx0">str-unfixed.txt 
    

    を私は強くC上のすべての単一のファイルを検索しませ示唆していることが追加されます。ファイルのワイルドカード/マスクを変更することで、何とかこれをフィルタリングする必要があります。

    関連する問題