import os, string , subprocess ,sys, platform, ctypes
from subprocess import PIPE, Popen

a = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
e=os.environ['SYSTEMDRIVE']
a.remove(e)
b= ''.join(a)
c = b.split(":")
for i in range(0,len(c)-1):
    d='Format-Volume -DriveLetter'+' '+c[i]
    process=subprocess.Popen(["powershell",d],stdout=subprocess.PIPE,stderr=subprocess.PIPE);
    out, err = process.communicate()

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)

def ecmd(command):
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = obj.communicate()
    ret=obj.returncode
    if ret==0:
        if out:
            return out
        else:
            return ret
    else:
        if err:
            return err.strip()
        else:
            return ret	

print type(platform.release())
print platform.release() == 7
if platform.release() == '7':
    path = os.environ['PROGRAMDATA'] +'\diskscript.txt'
    print path
    contents = """
       select disk 0
       clean
            """
    with disable_file_system_redirection(): 
        try:
            with open(path, 'w') as fiOb:
                fiOb.write(contents)
        except:
            print 'Fail: Check your path!!'

    if os.path.isfile(path):
        command=r'diskpart /s '+ path
        print ecmd(command)
print "Erased Successfully"
