In short, since Windows 7 and probably later, executable files are always unlocked no matter if they are loaded, and they need to be explicitly locked to prevent modification or deletion.
In Windows 9x and NT/XP, executable files are locked while running and they would need to be unlocked by some API call.
Probably it's a very basic way to determine/detect the Windows version as a rough approximate, at least in a practical way (trying to rename or write the executable file from itself).
Under Windows 95, 98 (9x) and XP (2000, NT...) we all remember that all executable files are automatically locked while they are running.
But under Windows 7, executable files seem to remain unlocked by default, which allows to delete, uninstall, modify, recompile or alter them in the file system at all times, no matter whether they are currently running or not.
Just try to compile a test program under Windows 7 and you will see that you can rename and even delete it (try running and then deleting a program like http://devel.archefire.org/tmp/ClockCount.zip).
Probably a program like Unlocker could be investigated to use a sequence of API calls that doesn't involve terminating the process:
http://www.emptyloop.com/unlocker/#download
This is the list of imported API calls of the Unlocker binary:
Ç ┤╪☺ n┌☺ \┌☺ ☼ GetModuleFileNameExW ♪ Ge
tModuleBaseNameW ♦ EnumProcessModules PSAPI.DLL ^ InitCommonControlsEx S Ima
geList_ReplaceIcon T ImageList_SetBkColor 8 ImageList_Create COMCTL32.dll WS
2_32.dll ö SHDeleteKeyA z PathSkipRootW ↨☺StrToIntA 9☺wvnsprintfA 0 PathFindE
xtensionW ¶☺StrStrW D PathIsDirectoryW r PathRemoveFileSpecW ☼☺StrStrA p Path
RemoveExtensionW | PathStripPathW ~ PathStripToRootW SHLWAPI.dll ╬♥lstrcmpiW
¶☺GetCommandLineW ╫♥lstrlenW d☺GetFileAttributesW ç DeleteFileW ┴☻RemoveDire
ctoryW !♥SetFileAttributesW ╕☺GetShortPathNameW ╤♥lstrcpyW m☻MoveFileW ☺☻Glo
balFree ♀☻GlobalUnlock ♣☻GlobalLock ◘☻GlobalReAlloc ·☺GlobalAlloc ╤ FindClos
e α FindNextFileW ╦♥lstrcmpW ╪ FindFirstFileW ü☺GetModuleHandleA 6 CloseHand
le è♥VirtualFreeEx û♥WaitForSingleObject m CreateRemoteThread ╨♥lstrcpyA ó☺Ge
tProcAddress │♥WriteProcessMemory ê♥VirtualAllocEx é☻OpenProcess X☻LocalFree
N☻LoadLibraryA ▒☻ReadFile ╩♥lstrcmpA }☺GetLongPathNameW Y CreateFileW ¬♥Wr
iteFile q☻MultiByteToWideChar δ☺GetVersionExA ╓♥lstrlenA l☻MoveFileExW û Dupli
cateHandle E☺GetCurrentProcess d♥TerminateProcess ò☻Process32NextW i☻Module32
NextW g☻Module32FirstW Ç☺GetModuleFileNameW ô☻Process32FirstW t CreateToolhel
p32Snapshot ¢☻QueryDosDeviceA V CreateFileA ╝ ExitProcess q CreateThread KERN
EL32.dll ▀☻wsprintfW Ö DestroyWindow ♥☻PeekMessageA í DispatchMessageA ▒☻Tra
nslateMessage Ö☻ShowWindow >☻SendMessageA ‼☺GetDlgItem U CreateDialogParamA
Γ☺MessageBoxA ╝ DrawTextA ♫☺GetDC ë☻SetWindowPlacement ╞ EndDialog w☺GetWind
owPlacement x☺GetWindowRect ♣☻PostMessageA ì☻SetWindowTextA Y☻SetDlgItemText
W X☻SetDlgItemTextA û DestroyIcon ┴☺LoadIconA ▬☺GetDlgItemTextW ₧ DialogBoxPara
mA 9☻SendDlgItemMessageA ├☻UpdateWindow û☺InvalidateRect \☺GetSysColor ∩☺Move
Window ☺☺GetClientRect @ ClientToScreen ▐☻wsprintfA 7 CharUpperW ← CallWindo
wProcA ò DestroyCursor å☻SetWindowLongPtrA G☻SetCapture R☻SetCursor ╜☺LoadCurs
orA ☼☻PtInRect ,☻ReleaseCapture _☺GetSystemMetrics USER32.dll ♫☻SelectObjec
t : CreateFontIndirectA ò☺GetObjectA GDI32.dll ♀ GetSaveFileNameW comdlg32.d
ll ♦☻RegSetValueExA ♣☻RegSetValueExW ╦☺RegCloseKey ╤☺RegCreateKeyExA ∞☺RegOp
enKeyExA ≈☺RegQueryValueExA Γ FreeSid 6☻SetNamedSecurityInfoW *☻SetEntriesInAc
lA ↔ AllocateAndInitializeSid ADVAPI32.dll • CommandLineToArgvW ¢ SHFileOpe
rationW å SHCreateDirectoryExW ╜ SHGetPathFromIDListW z SHBrowseForFolderW
╖ SHGetMalloc ◙☺ShellExecuteExW . ExtractIconExW •☺ShellExecuteA SHELL32.dll m
CoUninitialize ? CoInitialize ole32.dll