folder_path = "C:\Windows\Temp" ## provide your folder path here

import os
import subprocess
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)
with disable_file_system_redirection():
	def get_user():
		obj = subprocess.Popen("hostname",shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
		result,error=obj.communicate()
		if error:
			print(error)
		else:
			command = 'WMIC /NODE:"'+result.strip()+'" COMPUTERSYSTEM GET USERNAME'
			cmd = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
			result_1,error_1=cmd.communicate()
			if error_1:
				print(error_1)
			else:
				return result_1.strip().splitlines()
	user_list = get_user()
	if len(user_list) > 1:
		command = 'icacls "'+folder_path+'" /grant:r '+user_list[-1]+':(OI)(CI)(R,W) /t'
		obj = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
		result,error=obj.communicate()
		if error:
			print(error)
		else:
			print('Read/Write permission for the folder "'+folder_path+'" has been given to the user : "'+user_list[-1]+'".')
	else:
		print("No user found...")