Patrick99
(Fresh Scripter)
2016-02-23 09:42 PM
Bitlocker status in txt file

How can we manage it do get the bitlocker status (manage-bde -status c: > c:\temp\rtr.txt) in a file? I tried this with admin rights
Shell "cmd.exe /c " + "manage-bde -status > c:\temp\encryption.txt"
Sleep 5
Exit 0

but nothing in the encryption.txt file
Ipconfig/all > txt file works fine...


Glenn BarnasAdministrator
(KiX Supporter)
2016-02-23 11:37 PM
Re: Bitlocker status in txt file

A. Why the sleep? Seems unnecessary as Shell will wait for the command to complete.
B. Try the WSHPipe UDF - it will capture both STDOUT and STDERR. Your command only writes STDOUT. Just write the output to the screen to see what you get..
C. Does the command (with the redirection) work when you run it from the command line?

Glenn


ShaneEP
(MM club member)
2016-02-24 01:24 AM
Re: Bitlocker status in txt file

It is odd. I am getting the same results. I get text when run from command line, but nothing when i run the same thing from kix.

CMD line:
 Code:
manage-bde -status > c:\users\shane\desktop\testbde.txt
results in a txt file containing
 Quote:
BitLocker Drive Encryption: Configuration Tool version 10.0.10011
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

ERROR: An attempt to access a required resource was denied.

Check that you have administrative rights on the computer.
where as the following Kix:
 Code:
Shell "%comspec% /c manage-bde -status > c:\users\shane\desktop\testbde.txt"
results in an empty text file.


AllenAdministrator
(KiX Supporter)
2016-02-24 03:24 AM
Re: Bitlocker status in txt file

Mark my words... its the damn uac getting in the way.

BradV
(Seasoned Scripter)
2016-02-24 12:11 PM
Re: Bitlocker status in txt file

You might need to catch stderr output. See redirect stderr

Glenn BarnasAdministrator
(KiX Supporter)
2016-02-24 03:11 PM
Re: Bitlocker status in txt file

When I run this from Kix, STDERR reports
 Code:
'C:\Windows\System32\manage-bde.exe' is not recognized as an internal or external command, operable program or batch file.
The error is not reported when run directly from the command line.

One thing to consider - Kix is a 32-bit app, and the Shell command calls the 32-bit shell environment via SYSWOW File Redirection. It's possible that the command won't run there. I've encountered this before and I recall there's a workaround.. I'll need to go dig into the code that I wrote.

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2016-02-24 03:21 PM
Re: Bitlocker status in txt file

OK - just tested this and it's damned simple!
 Code:
; save the original setting and turn x64 File Redirection off
$WFR = SetOption('WOW64FileRedirection', 'off')
;
; run your 64-bit commands
;
; restore the original setting
$WFR = SetOption('WOW64FileRedirection', $WFR)
Glenn


NTDOCAdministrator
(KiX Master)
2016-02-24 07:29 PM
Re: Bitlocker status in txt file

Simple when you know the available commands :-)

Glenn BarnasAdministrator
(KiX Supporter)
2016-02-24 07:59 PM
Re: Bitlocker status in txt file

Yeah, but the real issue became apparent when you saw the STDERR messages, which Brad and I referenced earlier.

It's something we need to be more cognizant of, with many of the current command-line tools working fine at the command line but not when called from scripts.

Glenn


ShaneEP
(MM club member)
2016-02-25 01:50 AM
Re: Bitlocker status in txt file

Sadly, the thought of it being a 32/64 bit issue never crossed my mind. But it indeed resolved the issue.

Patrick99
(Fresh Scripter)
2016-02-25 12:46 PM
Re: Bitlocker status in txt file

yes, indeed all solved... Thanks!