NSIS RMDir when dir is open in file manager - nsis

I have an uninstaller where dirs are removed with RMDir and RMDir /r. While debugging i realized that both functions are not working if the dir is opened in a file manager like windows explorer. The dir is not deleted.
Why does this happen. What can i do against this?

From the documentation:
If /REBOOTOK is specified, any file or directory which could not have been removed during the process will be removed on reboot

Related

NSIS script - Uninstall.exe file alone not getting deleted

I am using the below statements to delete the files and subdirectories from the installed directory.
RMDir /r "$INSTDIR\*.*"
RMDir "$INSTDIR"
While uninstalling, it doesn't delete the uninstall.exe file alone from the installed directory.
Please let me know your suggestions on this.
Have you tried the /REBOOTOKflag?
Take notice of this warning from the scripting reference:
Warning: using RMDir /r $INSTDIR in the uninstaller is not safe.
Though it is unlikely, the user might select to install to the Program
Files folder and so this command will wipe out the entire Program
Files folder, including other programs that has nothing to do with the
uninstaller. The user can also put other files but the program's files
and would expect them to get deleted with the program. Solutions are
available for easily uninstalling only files which were installed by
the installer.

Windows Error Deleting node_modules Folder: Source Path Too Long

I've made the switch to use npm/gulp in Visual Studio on Windows. However, removing the associated files has been painful in that I cannot easily delete the node_modules folder.
When trying to delete a folder hierarchy for a solution using Windows Explorer, I get the following "Source Path Too Long" dialog:
From there, I've tried using the Windows command prompt to delete using
rmdir /s /q node_modules
which may or may not work. When it doesn't work, the errors look something like
(snip)
~1\NODE_M~1\read-pkg\NODE_M~1\PATH-T~1\readme.md - The file name is too long.
node_modules\GULP-I~2\NODE_M~1\imagemin\NODE_M~1\IMAGEM~1\NODE_M~1\OPTIPN~1\NODE_M~1\logalot\NODE_M~1\squeak\NODE_M~1\LPAD-A~1\NODE_M~1\meow\NODE_M~1\redent
\NODE_M~1\INDENT~1\NODE_M~1\REPEAT~1\NODE_M~1 - The directory is not empty.
node_modules\GULP-I~2\NODE_M~1\imagemin\NODE_M~1\IMAGEM~1\NODE_M~1\OPTIPN~1\NODE_M~1\logalot\NODE_M~1\squeak\NODE_M~1\LPAD-A~1\NODE_M~1\meow\NODE_M~1\redent
\NODE_M~1\INDENT~1\NODE_M~1\REPEAT~1\package.json - The file name is too long.
(snip)
The only consistently successful way that I've found to remove the folder hierarchy is to go into subfolder after subfolder, renaming each folder to something short like 'a'. Eventually the path is short enough to allow deletion. This can waste quite a bit of time.
I've seen references to preventing the problem, but my question is about easily deleting the folder hierarchy that contains the problematic path length.
In short, the question is:
Is there a simple way to delete a folder hierarchy in Windows that gets the "Source Path Too Long" error?
This is the simplest option I've found so far:
npm install -g rimraf
then
rimraf node_modules
From there the folder hierarchy should be able to be deleted.
This option requires installing the rimraf package. A solution without needing the package would be nice, but I haven't found a simple one.
Robocopy can do this as well... Here is the Regkey I put in to be able to right click-> delete any folder using robocopy which will delete npm_module folders
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\RoboDelete]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\RoboDelete\command]
"Extended"=""
#="\"C:\\windows\\delfolder.bat\" \"%1\""
and here is the Bat file content
#echo off
if {%1}=={} #echo Syntax: DelFolder FolderPath&goto :EOF
if not exist %1 #echo Syntax: DelFolder FolderPath – %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%
endlocal
Hope this helps ..
For windows environment:
"scripts": {
...
"clean": "rmdir /s /q node_modules",
...
}
Either you can use - rimraf node_modules or rm -rf node_modules.
It works fine ;) :)

Folder in start menu/installation folder still exists,After uninstallation using NSIS script?

I have written nsis script for Java project.once i have clicked uninstaller.exe
Start menu >all programs >my application
all the files are removed successfully from location of installed.but the problem is, folder in STARTMENU/installation folder still exists,after clicking uninstallation.I dont know why this happened? I have used windows 7.
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
Delete /REBOOTOK $INSTDIR\uninstall.exe
I have used above code.Can anyone help me?
Where is the code to remove the directory? RMDir "$SMPROGRAMS\$StartMenuGroup"
It is also important to use RequestExecutionLevel so you don't run into compatibility issues...

NSIS uninstaller

Have some problems with NSIS uninstall code.
RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
In Windows 7 this code uninstall files from the folder, but don't uninstall the folder in Start Menu.
In Windows XP this code don't uninstall anything. It's just don't work.
Make sure that you aren't trying to RMDir the current working directory.
From the NSIS Documentation:
Note that the current working directory can not be deleted. The
current working directory is set by SetOutPath. For example, the
following example will not delete the directory.
SetOutPath $TEMP\dir
RMDir $TEMP\dir
Delete "$SMPROGRAMS\shortcut.lnk" -if u have any shortcut links
RMDir "$SMPROGRAMS\${PRODUCT_NAME} " -to remove the product entry from start menu
Delete all the sub entries like shortcuts first and then go for RMDir.

My NSIS script's Uninstall isn't deleting links from ProgramData directory

Got another newbie NSIS question. Here's the script:
; -*-nsis-*-
Name "ndhtest"
OutFile "FooStartMenuTest.exe"
XPStyle on
!define FOO_SRC c:\users\nhughes\foo
InstallDir "$PROGRAMFILES\Initech\"
Icon ${FOO_SRC}\foo_logo.ico
UninstallIcon ${FOO_SRC}\uninstall.ico
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
Section
SetOutPath $INSTDIR
File ${FOO_SRC}\foo.bat
WriteUninstaller "$INSTDIR\uninstall.exe"
CreateDirectory $SMPROGRAMS\Initech
CreateShortCut $SMPROGRAMS\Initech\Foo.lnk $INSTDIR\foo.bat "" \
"${FOO_SRC}\foo_logo.ico"
CreateShortCut $SMPROGRAMS\Initech\Uninstall.lnk $INSTDIR\uninstall.exe "" \
"${FOO_SRC}\uninstall.ico"
SectionEnd
Section "Uninstall"
Delete $SMPROGRAMS\Initech\Foo.lnk
Delete $SMPROGRAMS\Initech\Uninstall.lnk
RMDir $SMPROGRAMS\Initech
Delete $INSTDIR\Foo.bat
Delete $INSTDIR\uninstall.exe
RMDir $INSTDIR
SectionEnd
The uninstall seems to work except for leaving the shortcuts under ProgramData:
Directory of c:\ProgramData\Microsoft\Windows\Start Menu\Programs\Initech
08/10/2011 04:07 PM <DIR> .
08/10/2011 04:07 PM <DIR> ..
08/10/2011 04:23 PM 1,847 Foo.lnk
08/10/2011 04:23 PM 1,885 Uninstall.lnk
2 File(s) 3,732 bytes
2 Dir(s) 1,387,345,117,184 bytes free
What is my script getting wrong that is leaving this stuff hanging around?
Here is what the uninstaller writes to its console (I added a DetailPrint message listing $SMPROGRAMS):
smprograms=C:\Users\nhughes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Remove folder: C:\Users\nhughes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Initech\
Delete file: C:\Program Files (x86)\Initech\foo.bat
Delete file: C:\Program Files (x86)\Initech\uninstall.exe
Remove folder: C:\Program Files (x86)\Initech\
Completed
So the links under ProgramData never get referred to, it's looking for the links under AppData\Roaming instead.
I'm testing this on Windows 7, but the core problem here is I would like to be able to write a script that works on everything from XP to Windows 7, regardless of all the changes in how Windows squirrels away stuff in different spots in different versions. This is looking like it might be painful.
If DetailPrint is added to the nsis script, it starts to be apparent that NSIS tries to create the files under C:\Users, but they are actually created in c:\ProgramData. This ProgramData directory is a strange thing, because it's not visible with dir C:\, however it's possible to enter the directory with cd. Such mysteries are caused by Virtual Store, a tricky feature of Windows 7.
Now to the solution. Windows applications should define their execution level, otherwise system may behave in an unexpected way. You remember some applications ask whether to install "for current user only" or "for all users"? That's the thing we need to declare.
If we insert nsis instruction RequestExecutionLevel user, then the shortcuts are made for current user. If we do RequestExecutionLevel admin, then we should also add SetShellVarContext all to both install and uninstall sections.
This answer is based on the article from nsis wiki: Shortcuts removal fails on Windows Vista, where examples are given for both approaches.
From the spec:
4.9.1.8 RMDir
[/r] [/REBOOTOK] directory_name
Remove the specified directory (fully qualified path with no wildcards). Without /r, the directory will only be removed if it is completely empty. If /r is specified, the directory will be removed recursively, so all directories and files in the specified directory will be removed. If /REBOOTOK is specified, any file or directory which could not have been removed during the process will be removed on reboot -- if any file or directory will be removed on a reboot, the reboot flag will be set. The error flag is set if any file or directory cannot be removed.
Try adding the /r to the RMDir lines to force it to flush the contents. Either that or remove the links individually.

Resources