source: OGRE/trunk/ogrenew/SDK/Win32/WriteEnvStr.nsh @ 692

Revision 692, 2.7 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]1!include WinMessages.nsh
2
3!ifdef ALL_USERS
4  !define WriteEnvStr_RegKey \
5     'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
6!else
7  !define WriteEnvStr_RegKey 'HKCU "Environment"'
8!endif
9
10#
11# WriteEnvStr - Writes an environment variable
12# Note: Win9x systems requires reboot
13#
14# Example:
15#  Push "HOMEDIR"           # name
16#  Push "C:\New Home Dir\"  # value
17#  Call WriteEnvStr
18#
19Function WriteEnvStr
20  Exch $1 ; $1 has environment variable value
21  Exch
22  Exch $0 ; $0 has environment variable name
23  Push $2
24 
25  Call IsNT
26  Pop $2
27  StrCmp $2 1 WriteEnvStr_NT
28    ; Not on NT
29    StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:)
30    FileOpen $2 "$2\autoexec.bat" a
31    FileSeek $2 0 END
32    FileWrite $2 "$\r$\nSET $0=$1$\r$\n"
33    FileClose $2
34    SetRebootFlag true
35    Goto WriteEnvStr_done
36
37  WriteEnvStr_NT:
38      WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1
39      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
40        0 "STR:Environment" /TIMEOUT=5000
41 
42  WriteEnvStr_done:
43    Pop $2
44    Pop $1
45    Pop $0
46FunctionEnd
47
48#
49# un.DeleteEnvStr - Removes an environment variable
50# Note: Win9x systems requires reboot
51#
52# Example:
53#  Push "HOMEDIR"           # name
54#  Call un.DeleteEnvStr
55#
56Function un.DeleteEnvStr
57  Exch $0 ; $0 now has the name of the variable
58  Push $1
59  Push $2
60  Push $3
61  Push $4
62  Push $5
63 
64  Call un.IsNT
65  Pop $1
66  StrCmp $1 1 DeleteEnvStr_NT
67    ; Not on NT
68    StrCpy $1 $WINDIR 2
69    FileOpen $1 "$1\autoexec.bat" r
70    GetTempFileName $4
71    FileOpen $2 $4 w
72    StrCpy $0 "SET $0="
73    SetRebootFlag true
74   
75    DeleteEnvStr_dosLoop:
76      FileRead $1 $3
77      StrLen $5 $0
78      StrCpy $5 $3 $5
79      StrCmp $5 $0 DeleteEnvStr_dosLoop
80      StrCmp $5 "" DeleteEnvStr_dosLoopEnd
81      FileWrite $2 $3
82      Goto DeleteEnvStr_dosLoop
83   
84    DeleteEnvStr_dosLoopEnd:
85      FileClose $2
86      FileClose $1
87      StrCpy $1 $WINDIR 2
88      Delete "$1\autoexec.bat"
89      CopyFiles /SILENT $4 "$1\autoexec.bat"
90      Delete $4
91      Goto DeleteEnvStr_done
92
93  DeleteEnvStr_NT:
94    DeleteRegValue ${WriteEnvStr_RegKey} $0
95    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
96      0 "STR:Environment" /TIMEOUT=5000
97 
98  DeleteEnvStr_done:
99    Pop $5
100    Pop $4
101    Pop $3
102    Pop $2
103    Pop $1
104    Pop $0
105FunctionEnd
106
107#
108# [un.]IsNT - Pushes 1 if running on NT, 0 if not
109#
110# Example:
111#   Call IsNT
112#   Pop $0
113#   StrCmp $0 1 +3
114#     MessageBox MB_OK "Not running on NT!"
115#     Goto +2
116#     MessageBox MB_OK "Running on NT!"
117#
118!macro IsNT UN
119Function ${UN}IsNT
120  Push $0
121  ReadRegStr $0 HKLM \
122    "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
123  StrCmp $0 "" 0 IsNT_yes
124  ; we are not NT.
125  Pop $0
126  Push 0
127  Return
128
129  IsNT_yes:
130    ; NT!!!
131    Pop $0
132    Push 1
133FunctionEnd
134!macroend
135!insertmacro IsNT ""
136!insertmacro IsNT "un."
Note: See TracBrowser for help on using the repository browser.