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

Unknown said...

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

Anonymous said...

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

Tech Blog

Unknown 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

Vale Co Xenia said...



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

siva said...

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


Blogger said...

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

blog said...

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

Jhon said...

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.

Related Posts with Thumbnails