This worked to disable F4 function key (close window key) on Lenovo laptop.

Meaning the F4 key will not close window, but call default F4 action.

Install Auto Hot Key https://www.autohotkey.com and create new .ahk script with content:

;f4 and alt f4 switch
<!F4::
sleep 30
send {F4}
return
F4::!F4
Use AhkCompiller to convert script into .exe and run this .exe after Windows start, it will prevent Close function of the F4 key and instead call default F4 function.

I did it on Windows 10 but should work for all Windows.

You can also download already compilled .exe here: https://mega.nz/#!Vg92FYaB!4hhwNswnriy1LadsBXTg8B3Utvo9arA6zZclur7 nm-8