環境變量生效

REGEDIT4

HKEY_LOCAL_MACHINE\Software\文心軟件工作室]
@="文心工作室"
"姓名"="徐海斌"
"年齡"=hex:23
"婚否"=dword:00000000


一不做二不休,直接下載打開innosetup的代碼,搜索Environment,果真找到了。

很簡單:

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,LPARAM("Environment"), SMTO_ABORTIFHUNG, 5000, &MsgResult);


For example, on Windows NT-based systems, the following code fragment should propagate the changes to the environment variables used in the Command Prompt:
   SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,    (LPARAM) "Environment", SMTO_ABORTIFHUNG,    5000, &dwReturnValue);    None of the applications that ship with Windows 95 and Windows 98, including Windows Explorer and Program Manager, respond to this message. Thus, while this article can technically be implemented on Windows 95 and Windows 98, there is no effect except to notify third-party applications. The only method of changing global environment variables on Windows 95 is to modify the autoexec.bat file and reboot.


謝謝,已解決,不用重新編譯的版本.自己編譯很麻煩吧? 貌似原版都不支持sysutils裏的好多函數. 原來是沒有在正確的inno事件中調用. 方法設置ChangesEnvironment後,需要在正確的事件中調用,安裝時需要在以下調用 procedure CurStepChanged(CurStep: TSetupStep); begin if CurStep = ssInstall then _SetDelphiPath(True); end; 卸載時需要在以下調用: procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usUninstall then begin _SetDelphiPath(False); end; end; 之前的 procedure CurPageChanged(CurPageID: Integer); begin if CurPageID = wpFinished then ..... 調用時inno已經通知刷新系統變量了,所以不起作用.要在通知刷新之前調用,經過試驗前面兩個事件時機結果正確.

 

發佈了31 篇原創文章 · 獲贊 3 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章