2012-05-04 19 views
0

プロファイルフォルダの名前をtxtファイルにコピーし、各行(プロファイル)とクエリ広告を取り込むバッチを作成しようとしています。私が持っているように見える二つの問題があります:バッチ構文エラー

  1. それは私が、私はデバッグのためにそれを打破する場合、ループは単に変数を設定しているようだループ
  2. のための私を書いた方法で、構文エラーがあると言います何度も繰り返し、その後、添字でコマンドを実行するだけ
@echo off 

@setlocal enabledelayedexpansion 
pushd "c:\documents and settings" 

mkdir c:\pulls 
copy \\mint\testfolder\forfiles.exe c:\pulls\ 
copy \\mint\testfolder\psexec.exe c:\pulls\ 
rem call \\mint\testfolder\copy.bat c:\pulls\ 
set queryid= 
set checkid= 

rem finds all profiles that have been logged into in the last 18 months 

c:\pulls\forfiles.exe /p "c:\documents and settings\" /d -540 /c "cmd /c if @ISdir==true deltree @isdir" 

dir/b > "c:\documents and settings\profiles.txt" 

%queryid% > "c:\documents and settings\tmp.txt" 

rem active directory query 

:adquery 

for /f "tokens=*" %%n IN ("c:\documents and settings\profiles.txt") do (
    set queryid=%%n 
    call :sub 
) 


goto :end 

:sub 

c:\pulls\psexec.exe \\computer-u domain\user -p password dsquery user -name %queryid%  > "c:\documents and settings\tmp.txt" 
set /p checkid= < "c:\documents and settings\tmp.txt" 
del "c:\documents and settings\tmp.txt" 


::checks to see if variable is an empty string 

if [!%checkid%==!] goto :process1 

if [%checkid%==] %queryid% >> c:\documents and settings\final.txt 

goto :eof 

:process1 

c:\pulls\psexec.exe \\computer -u domain\user -p password dsquery user -name %queryid%  -desc *termed* > "c:\documents and settings\tmp.txt" 
set /p checkid= < "c:\documents and settings\tmp.txt" 
del "c:\documents and settings\tmp.txt" 

::checks to see if variable is an empty string 

if [!%checkid%==!] goto :amending 
if [%checkid%==] goto :process2 

goto :eof 

:process2 

c:\pulls\psexec.exe \\computer -u domain\user -p password dsquery user -name %queryid%  -disabled > "c:\documents and settings\tmp.txt" 
set /p checkid= < "c:\documents and settings\tmp.txt" 
del "c:\documents and settings\tmp.txt" 

::checks to see if variable is an empty string 

if [!%checkid%==!] goto :amending 

goto :eof 

:amending 

%checkid% >> "c:\documents and settings\final.txt" 

goto :eof 

:end 

notepad.exe "c:\documents and settings\final.txt" 

del c:\pulls /y 

del "c:\documents and settings\profiles.txt" 

del "c:\documents and settings\final.txt" 

rem copies selected profiles 

rem c:\pulls\copy.bat 

答えて

1

を最終的な値を使用して、私はあなたが他の問題を持っているかどうかを確認するためにあなたの全体のロジックをトレースしていません。しかし、私はあなたのFOR/Fループの問題を特定しました。

ファイルを読み込もうとしていますが、IN()節は二重引用符で囲まれているため、ファイル名ではなく文字列として解釈されます。 (FORコマンドのヘルプについては、FOR /?を入力してください)。パスに空白が含まれているので二重引用符を使用したいが、ファイル名として解釈する必要がある。これがUSEBACKQオプションの目的である!

for /f "usebackq tokens=*" %%n IN ("c:\documents and settings\profiles.txt") do ...