#!/usr/bin/env python
# coding: utf-8

# In[ ]:


#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
import os
import re
from subprocess import PIPE, Popen
drive=itsm.getParameter('Drive')  ##Enter the Drive you want to encrypt eg: D:
networkdrive=itsm.getParameter('networkDrive')
file_name='bitlocker.txt'
file_path=os.path.join(os.environ['TEMP'], file_name)
def ecmd(command):
    import ctypes
    from subprocess import PIPE, Popen
    
    class disable_file_system_redirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))
        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)
    
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
	out, err = obj.communicate()
	print out
	print err
    ret=obj.returncode
    if ret==0:
        if out:
            return out.strip()
        else:
            return ret
    else:
        if err:
            return err.strip()
        else:
            return ret

import ctypes
class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

import subprocess

path = 'C:\\Windows\\System32\\manage-bde.exe -status '+drive
with disable_file_system_redirection():
    process=subprocess.Popen((path),shell=True,stdout=subprocess.PIPE);
result=process.communicate()[0]
print result
protect=re.findall('Lock Status:          (.*)',result)
pro="".join(protect)
if "Unlocked" in pro:
	print ecmd('manage-bde -on '+drive+' -rp -sk '+networkdrive+' -skiphardwaretest >>'+file_path)
	print ecmd('move '+file_path+' '+networkdrive)
	print "Encryption In Progress"
	import time
	time.sleep(1200) 
	print "Bitlocker values stored in %s"%networkdrive
	print "Sucessfull"


