Wizard lock

Wizard lock is a magical way to close and lock a door; in doing so it repairs broken doors, and it can even create a locked door in an empty doorway. This spell is useful for creating a barricade between you and some monsters, so that the monsters are unable to enter or exit a room of the main Dungeons of Doom. No monsters can open lock doors; only a few can pass them through other means.

Wizard lock is a spell from the spellbook of wizard lock, but zapping a wand of locking has the exact same effect.

Wizard lock will also repair and engage the locks on chests and large boxes. This use causes no benefit, but it must work because The DevTeam Thinks Of Everything. Locking a chest or large box does nothing to protect your stash, because at present, no monsters in NetHack 3.4.3 ever try to open a container, locked or not. It only inconveniences you or wastes a wand charge because you have to unlock or pry open the container again to add to or remove from its contents. (Any gelatinous cube swallowing a container cares not whether it was locked.)

Strategy
Few characters will find a spellbook of wizard lock early in the game, when it is most useful. A few other characters will find a wand of locking but will need to identify it. It is good practice to be engrave-testing your wands; five types of wands do nothing special when engraving (including the wand of secret door detection unless it detects something). Test these wands by zapping them toward an unlocked door or doorway.

Okay, you learned wizard lock or found the spell. Then you will find it most useful in the Dungeons of Doom and in Minetown, the places that contain many rooms with doors. When fleeing away from monsters, if you pass into or out of a room, you can use wizard lock to stop monsters from chasing you. When most monsters, chasing after that adventurer, discover a locked door coalesce in the corridor in front of them, the monster in front will lean against the door waiting for you to open it again or reappear somewhere else.

In Minetown
Minetown has many rooms; wizard lock can be an important lifesaver if you need to lock yourself in a room to heal, or if you need to lock some monsters in a room. Most players will find and use a skeleton key for this purpose. If you broke one of the doors, then wizard lock may be useful even though a key is not.

Caveats
Wizard lock is but one strategy of many, and sometimes it will not work.

Remember though that if you cannot use wizard lock in one place, then you might retreat some more and use wizard lock against the next available door or doorway.

Doorways versus empty squares
Wizard lock only creates locked doors on squares that NetHack believed were doors or doorways. Not every square is a doorway. A doorway is an empty square on the boundary of a room, regardless of whether NetHack generated it that way or something dug away the wall. Most doorways are in the Dungeons of Doom and in the other places with rectangular rooms. You will not find doorways in places that are not made from rooms, such as the Gnomish Mines.

If something digs away walls in the Dungeons of Dooms, then you may use wizard lock to fill the gaps with locked doors. If something digs away walls in the Gnomish Mines, then wizard lock is of no use.

Objects where the door would be

 * This section is a guess, and needs verification.

Any single object can prevent a door from closing. If you want to use wizard lock to create a door on a certain square, then you need to remove any objects from there. This is mostly an issue if you want to lock a door after slaying some monster there, and the monster dropped something. If the monster dropped a heavy corpse or a loadstone, then you might be not able of clearing the square.

Monsters that can pass locked doors
Monsters such as ghosts and xorns can pass through doors. Blobs and puddings can squeeze themselves underneath doors.

Other than xorns, most of these monsters are slow and weak, so you should still be able to flee them. Perhaps you might fight one, knowing that the other monsters remain stuck behind the door.

Monsters with wands of striking
If a monster happens to carry a wand of striking, then they might break down a locked door. Currently monsters do not aim for locked doors, but they might zap at you and hit the door by accident.