2016年12月7日 星期三

How to add a Uninstall option in Visual Studio Setup project without writing code

Visual Studio 建立Uninstall反安裝程式設定

1) In the Setup Project –> File System windows –> Right Click “File System on Target machine” –> add a Special Folder, select System Folder;

2) Into this system folder Add a file. Browse for msiexec.exe from local System32 folder and add it. Override default properties of this file as follows:

Condition:=Not Installed (make sure you put ‘Not Installed’ exactly like that, same case and everything),
Permanent:=True,
System:=True,
Transitive:=True,
Vital:=False.

3) Create a new shortcut under the ‘Users Program Menu’, Set Target to the System Folder which you created in the step 1. and point it’s at the msiexec.exe. Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].

5) Build the project, ignore warning about the fact that msiexec should be excluded, DONT exclude it or the setup project wont build.

The ‘Not Installed’ condition and Permananet:=True ensure that the msiexec.exe is only placed into the system folder as part of the install IF it doesn’t aready exist, and it is not removed on an uninstall – therefore it;s pretty safe to ignore that warning and just go for it.

(Based on the description from SlapHead)

 

【Step1】

  • File System on Target machine按右鍵新增一個add a Special Folder,選擇System Folder。

【Step2】

  • System Folder按右鍵新增file,在你電腦系統裡找一個msiexec.exe,如果不知道就用搜尋的,基本上放在System32 folder裡。
  • 接下來設定msiexec.exe的參數:
  • Condition = Not Installed(自行KEY上)
  • Permanent = True
  • System = True
  • Transitive = True
  • Vital = False

【Step3】

  • 在msiexec.exe按右鍵建立一個捷徑(shortcut),然後移到你要顯示的資料夾中,這裡是移到Users Program Menu底下的Marc資料夾,請自行修改名稱Uninstall XXX。
  • 接下來在Uninstall XXX的屬性Arguments增加" /x {ProductCode}"(記得/x後要加空白鍵),ProductCode在setup屬性底下找的到,類似{B52B1687-DC77-48F4-A842-2AD7B45C7EAA}

【Step4】
  • 只要Build就完成了

沒有留言: