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:

farhan khwaja said...

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..

Delwar said...

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..

Ava joseph said...

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

liferay development and liferay portal

Erick Jhonson said...

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

seattlesciencef said...

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

Tech Blog

Teechnical Anaalysis said...

Pretty great post. I simply stumbled upon your weblog and wanted to say that I have really loved browsing your weblog posts. In any case I will be subscribing in your feed and I'm hoping you write once more very soon!
http://www.iwalkusa.com/

Aarav sinha said...

Thanks For Share this information !!

I am using one android call recorder application, This application facilitates you with an option of auto upload which allows you to mechanically upload files on server, including Google drive, Dropbox, Gmail inbox, Evernote and sound cloud.

asa akter said...

T20 CRICKET WORLD CUP 2016
SNEAK PEAK AT ICC T20 WORLD CUP CHAMPIONS SINCE INCEPTION IN 2007
India vs Pakistan ICC T20 World Cup 2016 Match preview, Live streaming, Live Score, Watch Online
South Africa Cricket Team Squad, Players for ICC T20 World Cup 2016
New Zealand One of the contenders for the T20 World Cup 2016
ICC T20 WORLD CUP 2016 (INDIA) TOP TEN VALUABLE CRICKETERS |BATSMAN RANKING|
ICC T20 World Cup 2016 Schedule

Jasmine F said...

ICC World Twenty20 2016
icc t20 world cup live streaming free
ICC World Twenty20 Live
t20 world cup live
watch icc t20 world cup live streaming
icc t20 world cup live video streaming
icc t20 world cup live streaming espn
icc t20 world cup live streaming on youtube
t20 world cup opening ceremony live
20 20 world cup live
t20 live streaming
icc t20 world cup 2016
t20 cricket live streaming
t20 world cup live stream
icc t20 world cup live streaming
icc t20 world cup 2016 live streaming
icc t20 world cup 2016
t20 world cup live streaming
icc t20 world cup highlights
t20 world cup highlights
india vs new zealand t20 world cup live streaming
india vs new zealand t20 match live streaming
india vs new zealand t20 world cup live
india vs new zealand t20 cricket match live streaming
india vs pakistan t20 world cup live streaming
india vs pakistan t20 world cup match
india vs australia t20 world cup live
india vs australia t20 cricket match live streaming
t20 world cup live score
ICC World Cup Twenty 2016
icc t20 world cup 2016
t20 world cup 2016
t20 world cup
icc t20 world cup
world cup t20

Richard Carroll said...

Good Post, Call at Hotmail Technical Support NZ +64-98890480 for Help & Support for Hotmail users.

Related Posts with Thumbnails