import os
from subprocess import PIPE, Popen
import ctypes
import time 
start =time.time()
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)

            
check=os.popen("""wmic product where "name like 'FortiClient'" get name""").read()
if "FortiClient" in check:
    print("FortiClient product is present Unistalling Starting ")
    bat_file="""
wmic product where "name like 'FortiClient'" call uninstall /nointeractive | wmic  && shutdown -a && shutdown -r -t 120 """
    with open(r"C:\forticlientunistaller.bat","w") as f:
        f.write(bat_file)
    with disable_file_system_redirection():
        obj=Popen(r"C:\forticlientunistaller.bat")
    r,e=obj.communicate()
    if e:
        print e
    else:
        print r
else:
    print("FortiClient product is not present")

end=time.time()
print("Execution Time: %s"%(end-start))