View Single Post
Old 5th October 2015, 08:00   #296
Mircea M
Junior Member
Join Date: Aug 2014
Posts: 44
Rename command fails although there's no lock


I noticed a while ago that in case I am trying to rename a folder that is currently open in Windows Explorer, the operation sometimes fails. In order to try and figure out what is happening, I created a small script that uses the LockesList plugin (to see if anything is really locked):

Name `LockedList Test`

OutFile LockedListTest.exe
RequestExecutionLevel admin

!define origFolder "C:\Program Files (x86)\Original"
!define newFolder "C:\Program Files (x86)\Original_Renamed"

Page Custom LockedListShow
Page instfiles

Function LockedListShow
LockedList::AddFolder "${origFolder}"
LockedList:ialog /autonext /searching "Searching for locked files in ${origFolder}"
Pop $R0
MessageBox MB_OK "$R0"

Function renameFolder
MessageBox MB_OK "Renaming ${origFolder} to ${newFolder}"
Rename "${origFolder}" "${newFolder}"
IfErrors 0 done
MessageBox MB_OK "Failed to rename"

Call renameFolder

I also have the following folder structure:
I then execute LockedList.exe in different scenarios.
  1. All Windows Explorer windows closed
  2. Windows Explorer open with folder "Original" displayed
  3. Notepad open with Test.txt
  4. Windows Explorer open with folder Original\config displayed

Here are the results:
Case 1: LockedList returns "next" as no locks found, folder is renamed
Case 2: LockedList returns "next" as no locks found, folder is renamed
Case 3: LockedList displays Notepad.exe as a lock. I close it and it then returns "next". Rename failes (as folder Original\config displayed in Windows Explorer - since I opened the txt file)
Case 4: LockedList returns "next" as no locks found, rename failes.

Now I found this a bit "weird". Rename works ok if only the folder to be renamed is displayed in Windows Explorer but fails as soon as any subfolders thereof are displayed. Also, LockedList finds no locks and manual renaming also works.

Any idea why this might happen? Is this a problem with the plugin maybe (that it doesn't detect these locks)? Or with NSIS, since every other rename works when it reports that the files are locked?

Mircea M is offline   Reply With Quote