2011-08-10 82 views
2

得到另一個新手NSIS問題。這裏的腳本:我的NSIS腳本的卸載不是刪除從ProgramData目錄的鏈接

; -*-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 

卸載似乎除了留下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 

什麼是我的腳本越來越錯誤是離開這個東西掛?

下面是卸載程序寫入其控制檯(我加了一個DetailPrint消息,列出$ 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 

所以ProgramData下的鏈接永遠不會提及,它在尋找下應用程序數據\漫遊鏈接代替。

我在Windows 7上測試了這個,但這裏的核心問題是我希望能夠編寫一個適用於從XP到Windows 7的所有內容的腳本,無論Windows如何將東西松動在不同版本中的不同位置。這看起來可能會很痛苦。

+0

這是怎麼回事? XP? Vista嗎? Windows 7的? – Femi

+0

它在Windows 7上 –

回答

2

如果DetailPrint被添加到nsis腳本,它開始顯而易見NSIS試圖創建C:\Users下的文件,但它們實際上是在c:\ProgramData中創建的。這ProgramData目錄是一個奇怪的事情,因爲它不可見dir C:\,但可以輸入目錄cd。這種謎團是由虛擬商店引起的,這是Windows 7的一個棘手的特性。

現在就來解決問題。 Windows應用程序應該定義它們的執行級別,否則系統可能會以意想不到的方式運行。你還記得一些應用程序詢問是否安裝「僅適用於當前用戶」還是「適用於所有用戶」?這是我們需要聲明的事情。

如果我們插入nsis指令RequestExecutionLevel user,則爲當前用戶創建快捷方式。如果我們執行RequestExecutionLevel admin,那麼我們也應該將SetShellVarContext all添加到安裝和卸載部分。

本答案基於nsis wiki上的文章:Shortcuts removal fails on Windows Vista,其中給出了兩種方法的示例。

0

從規格:

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. 

嘗試添加/r到RMDIR線,迫使它刷新內容。要麼或單獨刪除鏈接。

+0

他刪除了他創建的所有文件,因此不需要/ r開關。問題是目錄被映射並且快捷方式在不同的地方被創建。使用'RMDir/r'時請非常小心。它應該是非常好的想法,而不是魯莽地應用。 – Jarekczek