NSIS 设置系统变量

定义

 ; include for some of the windows messages defines
   !include "winmessages.nsh"
   ; HKLM (all users) vs HKCU (current user) defines
   !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
   !define env_hkcu 'HKCU "Environment"'

 

设置

   WriteRegExpandStr ${env_hklm} "MongoBin" "D:\Philips\mongodb\bin"
   ; and current user
   WriteRegExpandStr ${env_hkcu} "MongoBin" "D:\Philips\mongodb\bin"
   ; make sure windows knows about the change
   SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000  

 

卸载时代码

  ; delete variable
   DeleteRegValue ${env_hklm} "MongoBin"
   DeleteRegValue ${env_hkcu} "MongoBin"
   ; make sure windows knows about the change
   SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

 

 

在CMD中使用方式:

使用 %MongoBin% 即可得到 D:\Philips\mongodb\bin的值

posted @ 2017-06-06 15:37  碎心炼心  阅读(1118)  评论(0)    收藏  举报