English 中文(简体)
Trouble with FOR /F loops inWindows Batch files
原标题:Trouble with FOR /F loops in Windows Batch Files

So I am trying to create a batch file that will do different things depending on the output of another program. Basically, the first program outputs some information on the encryption status of the hard drive. Here is the output when a drive is not encrypted

S:>beinvvol.exe xlc
------------------------------------------------------------------------
BEInvVol, Utimaco Safeware AG - A member of the Sophos Group
Decommissioning Tool for fully SGN-encrypted Volumes
------------------------------------------------------------------------

&Info: SGN filter driver off
&Info: Target log-file "S:BEInvVol.log"

------------------------------------------------------------------------
Listing info for the target volume(s) -command xlc
Date: 2011-07-26 13:31:01

[Volume C:]
Drive Type: DRIVE_FIXED
[Boot Sector]
Media Type: Plain -not SGN
Media Label:
Media Serial Number: {8C19-DCCD}
File System: NTFS
Size: 232.88 GB

这里是你在驾车被加密时得到的东西。

S:>beinvvol.exe xle
------------------------------------------------------------------------
BEInvVol, Utimaco Safeware AG - A member of the Sophos Group
Decommissioning Tool for fully SGN-encrypted Volumes
------------------------------------------------------------------------

&Info: SGN filter driver off
&Info: Target log-file "S:KeyDestroyBEInvVol.log"

------------------------------------------------------------------------
Listing info for the target volume(s) -command xle
Date: 2011-07-26 12:41:48

[Volume E:]
Drive Type: DRIVE_FIXED
[Boot Sector]
Media Type: SGN -fully encrypted
SGN Media GUID: {83490018-50C3-B4E3-829E-ACE3B23C86D3}
File System: NTFS
Size: 298.09 GB
[KSA Original]
Sector Offset ..... 0x0000000000065ED8 (417496)
Byte Offset ....... 0x000000000CBDB000 (213757952)
Size in Sectors ... 0x15 (21)
Size in Bytes ..... 0x2A00 (10752)
[KSA Backup]
Sector Offset ..... 0x000000002542D660 (625137248)
Byte Offset ....... 0x0000004A85ACC000 (320070270976)
Size in Sectors ... 0x15 (21)
Size in Bytes ..... 0x2A00 (10752)

“xlc”和“xle”论点是选择驱动力。 因此,我认为,在无加密的驱动力中,“媒体类型:”我有“Plain-not SGN”和加密驾驶人,我有“SGN - 完全加密”

现在,我试图写上“Plain-not SGN”的表格/表格,然后把它交给档案的不同部分。 这里是我迄今为止的施稿:

@ECHO OFF
::Determine if drive is encrypted
FOR /F "tokens=3,4,5 delims= " %%A IN ( S:einvvol.exe xlc ) DO IF /I "%%A%%B%%C"=="Plain-notSGN" GOTO NOTENCRYPTED

:ENCRYPTED
ECHO Yes
GOTO END

:NOTENCRYPTED
ECHO No

:END

现在,我的想法是,把名单中的第3、第4和第5条标注(关于I m有兴趣,第1号标注为“Media”,第2条是“Type:”,第3、第4和第5条要么是“Plain”“not”和“SGN”或“SGN”“-ful”“encodeed”,然后看这些指示是否等于“Plain-notSGN”(调整所有这些指示)。 然而,这并不奏效。 任何建议?

最佳回答
问题回答
::Test the file passed in via command line
FOR /F "usebackq tokens=4" %%G IN (`S:einvvol.exe xlc ^| FIND "-not"`) DO (
  IF "%%G"=="-not" GOTO NOT_ENCRYPTED
)

:ENCRYPTED
ECHO Yes
GOTO END

:NOT_ENCRYPTED
ECHO No

:END

Try:

@Echo off
::Test the file passed in via command line
FOR /F "tokens=3,4,5 skip=15" %%G IN (%1) DO IF Plain-notSGN == %%G%%H%%I GOTO NOT_ENCRYPTED

:ENCRYPTED
ECHO Yes
GOTO END

:NOT_ENCRYPTED
ECHO No

:END

你可能需要先管,或将贵功能的结果转至文本档案,但这似乎成功地区分了你所公布的两项成果。





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...