Saturday, August 13, 2011

NSIS - How to Write the Uninstaller

If you know how to create an installer using NSIS, you'll probably want to know how to create the uninstaller too :)

So you have to write a section named "Uninstall" inside your .nsi script file.

section "Uninstall"  
  SetShellVarContext all
  Delete "$DESKTOP\Your Application.lnk"
  RMDir /r "$SMPROGRAMS\YourApp"
  RMDir /r "$INSTDIR"
  Delete $INSTDIR\uninstall.exe
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YourApp"
  
sectionEnd

In line 2 it sets ShellVarContext to all (all user's shell folder will be used). If not the default is current user's shell folder.  Next line deletes the desktop shortcut. Next 3 lines delete the installation folders. If you entered any registry keys during the installation then you can delete them here (line 7).

While having this "Uninstall" section in  your nsis script, you have to invoke it from your "Install" section. Then only the installation will write the uninstaller.   Here is a possible association of a installer section to the above uninstaller section.

Section "GENERAL"

  SetShellVarContext all
  #Installer body---------(creating desktop/start menu short cuts, granting permissions, etc)
  
  #Writing registry keys
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YourApp" "DisplayName" "Your Application"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YourApp" "UninstallString" "$INSTDIR\uninstall.exe"

  # create the uninstaller
  writeUninstaller "$INSTDIR\uninstall.exe"

SectionEnd





10 comments:

  1. HI, My self Farhan Khwaja.. I have a blog called Code 2 Learn where i write about CS, programing lang, algorithms etc tutorials.. If you are interested in writing for me as a guest blogger then mail me back..

    ReplyDelete
  2. your blog is on of the best blogs. I pass. I have blog which is also containing PowerPoint I am delivering every events that count.
    Objectives..

    ReplyDelete
  3. This is very nice medium of very useful subject and very good material. Keep it up.
    pst recovery

    ReplyDelete
  4. Anonymous1:30 PM

    Impressive blog, for sure majority of all reader really love this too. Thanks!

    Tech Blog

    ReplyDelete


  5. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

    ReplyDelete
  6. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me. I am a regular follower of your blog.
    Really very informative post you shared here. Kindly keep blogging.
    Java training in Btm layout
    Java training in Rajaji nagar
    Java training in Kalyan nagar
    Java training in Kalyan nagar
    Java training in Jaya nagar


    ReplyDelete
  7. As claimed by Stanford Medical, It is really the ONLY reason this country's women get to live 10 years longer and weigh an average of 42 pounds lighter than we do.

    (And really, it has totally NOTHING to do with genetics or some secret diet and EVERYTHING to about "how" they eat.)

    BTW, What I said is "HOW", not "WHAT"...

    TAP on this link to discover if this little quiz can help you unlock your real weight loss potential

    ReplyDelete
  8. thank u for good information with us. i was searching good information regarding for tech and found this blog as useful infromation. I know another good website which provides very relevant information about the techsoft

    ReplyDelete
  9. Nice Blog. This blog is very interesting and you provide the best information for users. I always visited your blog site. Thanks for your wonderful sharing.

    ReplyDelete