0
FOR /F "tokens=*" %%A IN ('gpresult /r ^| FIND "string"') DO SET Result=%%A  
if '%Result%'=='this is where the word string shows up'  
echo Success > %homepath%\Desktop\Success.txt  

文字列が一致しても、実際にはファイルをデスクトップに書き込みません。

4

3 に答える 3

0

あなたが必要です

setlocal enabledelayedexpansion

バッチファイルの先頭にあり、代わりに

'%Result%'=='this is where the word string shows up'

あなたが必要

'!Result!'=='this is where the word string shows up'

-注意してください!それ以外の %。それ以外の場合、バッチファイルが最初に解析されるときに%Result%が展開され、その時点でResult変数には何も含まれません。これらの変更は、forループ内になるまで解析を遅らせることを意味します。その時点で、適切に入力されます。

于 2013-02-25T16:56:32.447 に答える
0

echoと同じ行にある必要がありますif

if '%Result%'=='this is where the word string shows up' echo Success > %homepath%\Desktop\Success.txt

または括弧で囲みます:

if '%Result%'=='this is where the word string shows up' (
    echo Success > %homepath%\Desktop\Success.txt
)
于 2013-02-25T17:41:44.727 に答える
0

コードで setlocal enableddelayedexpansion を使用してみてください。次に、「!variable!」を使用して変数にアクセスします。「%変数%」の代わりに。また、%%A が必要なトークンを取得しているかどうかも確認してください。

于 2013-02-25T17:24:05.537 に答える