1

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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
skm
  • 5,015
  • 8
  • 43
  • 104

1 Answers1

0

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
)
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I tried to use it but the command window quickly appears and disappear (I already have `pause`) and nothing happens. – skm Jan 09 '17 at 10:24
  • The above is PowerShell, not batch. If you want batch, why did you tag your question [tag:powershell]? – Ansgar Wiechers Jan 09 '17 at 10:24
  • oh am sorry, I am a newbie in this and didn't actually realise the difference. – skm Jan 09 '17 at 10:31