Search code examples
batch-filecmdwindows-embedded

Get Write Protection Status using EWFMGR


I need to get the write protection status of C: drive using ewfmgr and enable the write protection if it is currently disabled.

I understand that the following command can give me the status of C: drive on CMD window

ewfmgr c:

but how do I store the value in a variable and check if the write proctection is currently disabled?

I need the following (pseudocode):

currentStatus = Somehow get the status of C:
if currentStatus = disable
ewfmgr -enable
shutdown -r

Solution

  • In PowerShell simply pass the output of ewfmgr C: through a Where-Object filter:

    ewfmgr c: | Where-Object {
      $_.Trim() -match '^state\s+disabled$'
    } | ForEach-Object {
      ewfmgr c: -enable
      shutdown -r
    }
    

    In batch use findstr in a for loop:

    @echo off
    for /f %%a in ('ewfmgr c: ^| findstr /i /r /c:"state  *disabled"') do (
      ewfmgr c: -enable
      shutdown -r
    )