ShortcutNames = itsm.getParameter('ShortcutNames') # give here the shortcut names with extension. 
#if you want to remove more than one shortcut, please seperate them with comma - ",". for example: google.url , Notepad++.lnk , Google Chrome.lnk

from subprocess import PIPE, Popen
import ctypes
import os

class Remove_Shortcut:
    
    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 executecmd(self,CMD):
        with self.disable_file_system_redirection():
            OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
            out, err = OBJ.communicate()
            if out:
                print(out)
            else:
                print(err)
    
    def remove(self,shortcutNames):
        Name_list = shortcutNames.split(",")
        users=os.popen("net users").read().split()[5:-4]
        fil_users=[i.strip() for i in users if i.strip()!="Administrator" and i.strip()!="Guest"]
        fil_users.append("Public")
        for shortcut in Name_list:
            for user in fil_users:
                if os.path.exists("C:\Users\%s"%(user)):
                    path = os.listdir("C:\Users\%s\Desktop"%(user))
                    out = list(filter(lambda n: shortcut.strip().lower() in n.lower(), path))
                    if out:
                        os.remove("C:\Users\%s\Desktop\%s"%(user,out[0]))
                        print("successfully removed the shortcut - %s"%("C:\Users\%s\Desktop\%s"%(user,out[0])))

shortcut_obj = Remove_Shortcut()

shortcut_obj.remove(ShortcutNames)
            