Archive: LockedList plug-in


LockedList plug-in
  An NSIS plugin to display or get a list of programs that are locking a selection of files that have to be uninstalled or overwritten.

http://nsis.sf.net/File:LockedList.zip

Stu


v0.2 - 11th July 2007
* Better percent complete indication.

Stu


Hi Afrow UK,

Even simple script

LockedList::AddFile /NOUNLOAD $SYSDIR\kernel32.dll"
LockedList::Dialog

doesn't work for me.

I get messages "Going to compile test program and then run it"
then "The file '$TEMP\nsz1325.tmp\Lock' is now locked. It will appear on the LockedList dialog page soon..." some dialog blinks and that's all.

The same result I've got with example provided with plugin.


Firstly, you're missing a quote and secondly that's a module not a file.

How about this script:

Name "LockedList Test"
OutFile "LockedListTest.exe"

!include MUI.nsh

!insertmacro MUI_PAGE_WELCOME
Page Custom LockedListShow

!insertmacro MUI_LANGUAGE English

Function LockedListShow
LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"
LockedList::Dialog
FunctionEnd

Section
SectionEnd


You'll get some garbage for the first program captions. I might be able to fix this.

Stu

Thank you for sample but it also doen't work for me.
It seems that the problem is exactly in LockedList::Dialog

I modified your sample adding three message boxes


Name "LockedList Test"
OutFile "LockedListTest.exe"

!include MUI.nsh

!insertmacro MUI_PAGE_WELCOME
Page Custom LockedListShow

!insertmacro MUI_LANGUAGE English

Function LockedListShow
MessageBox MB_OK "test1"
LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"
MessageBox MB_OK "test2"
LockedList::Dialog
FunctionEnd

Section
MessageBox MB_OK "test3"
SectionEnd


and I can see only two of them.

You're not going to see the 3rd one because the dialog stops execution of the installer until it is closed.
What exactly happens? Does the dialog not display?

Edit: Also, what OS are you on?

Stu


dialog doesn't appear. installer is closed after message box "test2" closed.

OS: WinXP SP2


That's interesting. I'm running Win XP SP2 also.

What happens if you don't use any AddFile/AddModules.

Stu


ok, sorry for delay with answer. I had to deal with something.
now I'm sure that the problem is in LockedList::Dialog

I have two vesions of script


Name "LockedList Test"
OutFile "LockedListTest.exe"

!include MUI.nsh

!insertmacro MUI_PAGE_WELCOME

!insertmacro MUI_PAGE_INSTFILES

Page Custom LockedListShow

!insertmacro MUI_LANGUAGE English

Function LockedListShow
MessageBox MB_OK "test1"
LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"
MessageBox MB_OK "test2"
LockedList::Dialog
FunctionEnd


Section "Install"
MessageBox MB_OK "test3"
SectionEnd


and


Name "LockedList Test"
OutFile "LockedListTest.exe"

!include MUI.nsh

!insertmacro MUI_PAGE_WELCOME

Page Custom LockedListShow

!insertmacro MUI_PAGE_INSTFILES


!insertmacro MUI_LANGUAGE English

Function LockedListShow
MessageBox MB_OK "test1"
LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"
MessageBox MB_OK "test2"
LockedList::Dialog
FunctionEnd


Section "Install"
MessageBox MB_OK "test3"
SectionEnd


the first one shows message boxes
"test3"
"test1"
"test2"

the second one
"test1"
"test2"

diff:
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
Page Custom LockedListShow

!insertmacro MUI_PAGE_WELCOME
Page Custom LockedListShow
!insertmacro MUI_PAGE_INSTFILES

we contact directly so I can help you debug plugin

I'm aware that it is the plugin yes.

My MSN is afrowuk at tiscali dot co dot uk

Stu


Located the problem thanks to daisywheel :)
Please be patient while we make sure everything is ok then I shall upload the updated version.

Stu


Uploaded v0.2 RC2.
http://nsis.sf.net/File:LockedList.zip

Stu


LockedList::AddModule /NOUNLOAD "$SYSDIR\module.dll"
LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"

in case file module.dll doesn't exist will result error in functionality - there will no dependencies found

in case we change order
LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"
LockedList::AddModule /NOUNLOAD "$SYSDIR\module.dll"

plugin will work in another manner. I don't think this is expected behaviour.


Found the problem. It was a bad array pointer. It wasn't the fact of the file not being there it was simply only taking the first file or module added with AddFile/AddModule.

I was also able to fix the captions problem. I noticed captions were being repeated over multiple processes aside from the garbage caption for the first few processes. Just needed a ZeroMemory in there.

Uploaded v0.2 RC3.
http://nsis.sf.net/File:LockedList.zip

Thanks again :)

Stu


One more suggestion. I'm not compeltely happy with results.
For example, I have two browser application run: Internet Explorer and Moxilla Firefox both on page http://nsis.sourceforge.net/File:LockedList.zip

also I use following code in a script


LockedList::AddModule /NOUNLOAD "$SYSDIR\kernel32.dll"
LockedList::Dialog

and as results I've got
WINAMP.COM | Forums - LockedList plug-in - Moxilla Firefox (firefox.exe)
for Moxilla Firefox
and
AutoSuggest Drop-Down (iexplore.exe)
for IE

Currently it grabs the first window caption for that process id by using EnumWindows. I'll look into it. Maybe I can check if the window is a child or not and if it is then skip it.

Stu


Realised that EnumWindows does not enumerate child windows anyway (that's what EnumChildWindows is for) so instead I'm checking to see if a window has the WS_SYSMENU style set (title bar). Now get the correct caption for Internet Explorer among others.

Uploaded v0.3:
http://nsis.sourceforge.net/File:LockedList.zip

I also documented the ::Unload function which has to be used to unload the plugin after calling SilentWait /NOUNLOAD /time #. Few other changes in the change log too.

Stu


Another suggestion.

Add horizontal scroll when long name is displayed.

For now horizontal scroll is added only together with vertical one (in some cases even when it's not necessary)

Roman


This isn't possible because the list box is actually a list view with a single hidden column set to the width of the box. The NSIS InstFiles page has the same thing. Another option would be to have a tool-tip like the InstFiles page...

Stu


You can use ListView_SetColumnWidth with LVSCW_AUTOSIZE, but I think the triple dot looks better. If someone wants to see the entire line, he could just hover over it instead of scrolling and then seeing just the end.


Yeh I agree.
How does NSIS work out how long the text being displayed is?
I'm guessing it's not just down to the number of characters...

Stu


Size of the list view minus the size of a scroll bar. Line 1568 of Source\exehead\ui.c.


Yeh I've got that already... sorry meant the dots, but now I'm guessing that the list view control adds those itself anyway!!

Stu


The list view automatically shows the dots, but you need LVS_EX_LABELTIP for it to show the tool tip.


Thanks found that in Ui.c too. Very neat that it's all provided :)

Uploaded v0.3 RC2:
http://nsis.sourceforge.net/File:LockedList.zip

Edit: Uploaded again as it had the test executable in the Zip (+50000 bytes or so)

Stu


Nice plugin and sources :)

Thanks !


During testing of various locked items, I found a minor quirk. The locking process was detected going away for the exe's, but when I exited explore (brought up inside the target install directory), that was not detected going away. I had to navigate back and then next again to repeat the locked file search to get past it to the install. Also during testing, I ran into an "out of memory" message that appeared in the dialog just before the process name. That only happened once and did not repeat itself during futher testing.


Paths
  It appears that the plugin doesn't try both short and long paths so both need to be added for files / modules that may be in use with either a long or short path. Might be a nice addition for the plugin to check both behind the scenes.

Better still would be the ability to match files / modules in use by file name and then compare the paths to verify they are the same. This would also cover the unlikely scenario where the path is a combination of both long and short. Also, files / modules names can be short.

Besides that all I can say is wow... this is an extremely useful plugin.

Thanks,
Robert


Ah right good find. I'll see what I can do about that when I've got some time.

I plan on adding a 'file name only' lookup for the plug-in as well, and also the ability to simply show windows that have the task bar style set.

Thanks

Stu


SilentSearch
  I just noticed that SilentSearch isn't working when the module is in use by another user. This is on Vista with fast user switching. Interestingly enough, LockedList::Dialog is able to find it.

Thanks again,
Robert


I shall see if I can reproduce this on my XP machine soon. I do not have Vista unfortunately. This is interesting though as they are both exactly the same code bases for both functions except one directs output to the stack and one to a list view control!

Stu


After a quick peruse of the code it appears that EnableDebugPriv is only called when using the internal ui (e.g. LoadDialog).

*edit* that is the problem


Oh right woops :S

Stu


LockedList Plug-in:

The accelerator keys do not work for the next/back buttons. Only the mouse works.


Our tester has been experiancing an intermitant crash in the LockedList.dll plug-in. The crash happens during initialization (dialog is showing 0% on progress) The image captures is too large to attach. Here is the script used:

;
; This function is called to display any locked files.
;
Function LockedListShow

;Creator function
!insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLElock)" "$(TEXT_IO_SUBTITLE2)"

LockedList::AddFile /NOUNLOAD "$INSTDIR\${PRODUCT_NAME}"
LockedList::AddModule /NOUNLOAD "$INSTDIR\${PRODUCT_NAME}\${PRODUCT_LAUNCHER_EXE}"
LockedList::Dialog

FunctionEnd

Here is the crash information:

LockedList.map

0001:00001891 ?EnumSystemModules@@YGHP6GHUFILE_INFORMATION@@J@ZJ@Z 10002891 f SystemEnum.obj
0001:00001a97 ?EnumProcessIds@@YGHP6GHKJ@ZJ@Z 10002a97 f SystemEnum.obj

offset from error signature: 000029b5
base of EnumSystemModules: 2891
-------------------------------------
124 relative --> Line 478

SystemEnum.asm

; 476 :
; 477 : // Get the file path of the module.
; 478 : if (GetModuleFileNameEx(hProcess, hModules[j], File.FullPath, MAX_PATH))

push 260 ; 00000104H
mov eax, DWORD PTR [eax]
mov DWORD PTR _File$54859[ebp], eax
lea eax, DWORD PTR _File$54859[ebp+4]
push eax
mov eax, DWORD PTR -24+[ebp]
push DWORD PTR [eax]
push esi
call DWORD PTR _GetModuleFileNameEx
test eax, eax
je SHORT $L54877


SystemEnum.cod
; Line 478
00109 68 04 01 00 00 push 260 ; 00000104H
0010e 8b 00 mov eax, DWORD PTR [eax]
00110 89 85 40 fd ff
ff mov DWORD PTR _File$54859[ebp], eax
00116 8d 85 44 fd ff
ff lea eax, DWORD PTR _File$54859[ebp+4]
0011c 50 push eax
0011d 8b 45 e8 mov eax, DWORD PTR -24+[ebp]
00120 ff 30 push DWORD PTR [eax]
00122 56 push esi
00123 ff 15 00 00 00
00 call DWORD PTR _GetModuleFileNameEx
00129 85 c0 test eax, eax
0012b 74 5c je SHORT $L54877
; Line 481


New version v0.4:
http://nsis.sourceforge.net/File:LockedList.zip

v0.4 - 27th September 2007
* Module or file names can now be just the file name as opposed to the full path.
* Folder paths are converted to full paths (some are short DOS paths) before comparison.
* Fixed typo in AddModule function (ModulesCount>FilesCount). Thanks kalverson.
* List view is now scrolled into view while items are added.
* List changed to multiple columns.
* Debug privileges were not being set under SilentSearch.
* Added /ignore switch that prevents the Next button being disabled.
* Added AddApplications to add all running applications to the list.
* Added processing mouse cursor.
* Added right-click context menu with Close and Copy List options.
* Added progress bar.
* Added default program icon for processes without an icon.
* Added code to resize controls for different dialog sizes.
I cannot reproduce that crash kalverson and by the looks of it it's out of my control, unless the module handle being passed is not valid. I could surround it by a try{} block but I am not keen on that idea.

Stu

Thank you Stu!


I have a question about the LockedList plugin. Does AddFile support searching an entire directory? I couldn't find where it specifically said it was supported in the readme. I wanted to know that this is an option, before I go and try to fix my installer problems using this plugin.

Hopefully it does, because this plugin looks awesome and is basically the perfect solution for what I'm trying to do.


You mean if the file is in a folder or possibly in sub folders?

Stu


Yes, I want it to search my entire application directory to make sure nothing is being used before I go and try to update files. I didn't see anywhere that said wildcards were supported, but if then are, then that is fantastic. Thank you!