Debian Codegraph @

Docs/src/usefulinfos.but

raw
1 \A{usefulinfos} Useful Information
2
3 \H{errorlevels}Error Levels
4
5 Like other applications, installers made by NSIS return error levels as a result of their execution. Checking the error level can be useful if you call an NSIS installer from another application or installer.
6
7 \b 0 - Normal execution (no error)
8
9 \b 1 - Installation aborted by user (cancel button)
10
11 \b 2 - Installation aborted by script
12
13 You can set the error level to other values using \R{seterrorlevel}{SetErrorLevel}.
14
15 Note that uninstallers copy themselves to the temporary directory and execute from there so the original uninstaller can be deleted. This means the error level the uninstaller sets is not available to the executing process, unless it simulates this copy process and executes the copied uninstaller. To simulate this process, use:
16
17 \c InitPluginsDir
18 \c CopyFiles $INSTDIR\uninstaller.exe $PLUGINSDIR
19 \c ExecWait '"$PLUGINSDIR\uninstaller.exe" _?=$INSTDIR' $0
20 \c DetailPrint "uninstaller set error level $0"
21
22 If you don't do this, you'll only be able to know if the uninstaller failed copying itself to the temporary directory.
23
24 \H{useful_add_uninst_infos}Add uninstall information to Add/Remove Programs
25
26 Create a key with your product name (or a GUID) under HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall to add entries to the "Add/Remove Programs" section in the Control Panel.
27 For Windows NT (NT4/2000/XP and later), it's also possible to create the key in the HKCU hive, so it will only appear for the current user.
28 There are several values you can write to key to give information about your application and the uninstaller.
29 Write a value using the \R{writeregstr}{WriteRegStr} command (for strings) or \R{writeregdword}{WriteRegDWORD} command (for DWORD values).
30
31 Example:
32
33 \c WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "DisplayName" "Application Name"
34 \c WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "UninstallString" '"$INSTDIR\uninst.exe"'
35
36 \s{Required values:}
37
38 \e{DisplayName} (string) - Name of the application \\<br\\>
39 \e{UninstallString} (string) - Path and filename of the uninstaller. You should \s{always} quote the path.
40
41 \s{Optional values:}
42
43 Some of the following values will not be used by older Windows versions.
44
45 \e{QuietUninstallString} (string) - Quiet uninstall command (\cw{"$INSTDIR\\uninst.exe" /S})
46
47 \e{InstallLocation} (string) - Installation directory ($INSTDIR) \\<br\\>
48 \e{DisplayIcon} (string) - Path, filename and index of the icon that will be displayed next to your application name
49
50 \e{Publisher} (string) - (Company) name of the publisher
51
52 \e{ModifyPath} (string) - Path and filename of the application modify program \\<br\\>
53 \e{InstallSource} (string) - Location where the application was installed from
54
55 \e{ProductID} (string) - Product ID of the application \\<br\\>
56 \e{RegOwner} (string) - Registered owner of the application \\<br\\>
57 \e{RegCompany} (string) - Registered company of the application
58
59 \e{HelpLink} (string) - Link to the support website \\<br\\>
60 \e{HelpTelephone} (string) - Telephone number for support
61
62 \e{URLUpdateInfo} (string) - Link to the website for application updates \\<br\\>
63 \e{URLInfoAbout} (string) - Link to the application home page
64
65 \e{DisplayVersion} (string) - Displayed version of the application \\<br\\>
66 \e{VersionMajor} (DWORD) - Major version number of the application \\<br\\>
67 \e{VersionMinor} (DWORD) - Minor version number of the application
68
69 \e{NoModify} (DWORD) - 1 if uninstaller has no option to modify the installed application \\<br\\>
70 \e{NoRepair} (DWORD) - 1 if the uninstaller has no option to repair the installation
71
72 If both NoModify and NoRepair are set to 1, the button displays "Remove" instead of "Modify/Remove".
73
74
75 \H{useful_system_plugin} Calling an external DLL using the System.dll plug-in
76
77 Some installers need to call functions in third-party DLLs. A prime example of this is when installing a Palm(TM) conduit.
78
79 \\<b\\>Some background about System.dll\\</b\\> \\<br\\>
80 The System.dll plug-in enables calling of external DLLs by using its 'Call' function. There are a number of other functions provided by System.dll but they will not be covered here. For more details about the other functions, lock the doors, take the phone off the hook, screw your head on *real* tight and head on over to the \L{../Docs/System/System.html}{System readme}.
81
82 \\<u\\>Data Types\\</u\\> \\<br\\>
83 System.dll recognises the following data types:
84
85 \b v - void (generally for return)
86
87 \b p - pointer (includes void*, HANDLE, HWND, UINT_PTR and so on)
88
89 \b i - int (a 32bit integer)
90
91 \b l - large integer (also known as int64)
92
93 \b t - text, string (LPTSTR, pointer to first character)
94
95 \b k - callback. See Callback section in system.html.
96
97 \b * - pointer specifier -> the proc needs the pointer to type, affects next char (parameter) [ex: '*i' - pointer to int]
98
99
100
101 \\<u\\>Mapping System.dll variables to NSIS script variables\\</u\\> \\<br\\>
102 There's not much point in being able to call an external function if you can't get any data back. System.dll maps function variables to NSIS script variables in the following way:
103
104 NSIS $0..$9 becomes System.dll r0..r9
105 NSIS $R0..$R9 becomes System.dll r10..r19
106
107 Each parameter is specified by type, input and output. To skip input or output use a dot. Examples:
108
109 String (pointer to a character array), input is 'happy calling':
110
111 \c t 'happy calling'
112
113 String (pointer to a character array), input is taken from $5 and changes to the array made by the callee are saved into $R8:
114
115 \c t r5R8
116
117 Pointer to an integer, value taken from $1 and put into $2:
118
119 \c *i r1r2
120
121 Pointer to a 64-bit integer, output pushed on stack, no input:
122
123 \c *l .s
124
125 Using System.dll::Call
126 To call a function in a third party DLL, the Call function is used like this:
127
128 \c System::Call 'YourDllName::YourDllFunction(i, *i, t) i(r0, .r1, r2) .r3'
129
130 The '(r0, .r1, r2) .r3' section at the end are the parameters that are passed between your DLL and your NSIS script. As can be seen in this parameters list, type and input/output can be separated. Each block of "(parms list) return value" overrides and/or adds to the last one. In this case, the first block specifies the types and the second specifies input and output.
131
132 \\<b\\>Before starting to code the NSIS script\\</b\\> \\<br\\>
133 Before you start to code any NSIS code you need to know the full prototype of the function you are going to call. For the purposes of this example, we will use the 'CmGetHotSyncExecPath' function from the Palm 'CondMgr.dll'. This function is used to return the full path of 'HotSync.exe'.
134
135 \\<u\\>Function Definition\\</u\\> \\<br\\>
136
137
138 int __stdcall CmGetHotSyncExecPath(TCHAR *pPath, int *piSize);
139
140 where
141
142 \b pPath is a pointer to a character buffer. Upon return, this is the path & file name of the installed HotSync manager.
143
144 \b piSize is a pointer to an integer that specifies the size (in TCHAR's), of the buffer referenced by the pPath parameter.
145
146 return values:
147
148 \b 0: No error
149
150 \b -1: A non-specific error occurred
151
152 \b ERR_REGISTRY_ACCESS(-1006):Unable to access the Palm configuration entries
153
154 \b ERR_BUFFER_TOO_SMALL(-1010): The buffer is too small to hold the requested information
155
156 \b ERR_INVALID_POINTER(-1013):The specified pointer is not a valid pointer
157
158
159 Also, if the buffer is too small the value in *int is the size (in TCHARs) that the buffer should be.
160
161 This function definition maps to the following System.dll definition:
162
163 CmGetHotSyncExecPath(t, *i) i
164
165 i.e. It takes a text variable, a pointer to int, and returns an int value.
166
167 \\<u\\>Using the external dll function\\</u\\> \\<br\\>
168 Now that we've sorted out what the function does and how it maps to the System.dll format we can use the function in a NSIS script.
169
170 First you have to change the output directory to that where the DLL you want to use is. It may also work if the DLL is in the system path but this hasn't been tested.
171
172 The following code fragment will install 'condmgr.dll' to a temporary directory, execute the CmGetHotSyncExecPath function and display returned data.
173 Save this script
174
175 \c Function loadDll
176 \c
177 \c SetOutPath $TEMP\eInspect ; create temp directory
178 \c File bin\CondMgr.dll ; copy dll there
179 \c StrCpy $1 ${NSIS_MAX_STRLEN} ; assign memory to $0
180 \c System::Call 'CondMgr::CmGetHotSyncExecPath(t, *i) i(.r0, r1r1).r2'
181 \c DetailPrint 'Path: "$0"'
182 \c DetailPrint "Path length: $1"
183 \c DetailPrint "Return value: $2"
184 \c
185 \c FunctionEnd
186
187
188 and this function produces the following output in the 'details' page:
189
190 Output folder: c:\\windows\\TEMP\\eInspect \\<br\\>
191 Extract: CondMgr.dll \\<br\\>
192 Path: "C:\\Dave\\palm\\Hotsync.exe" \\<br\\>
193 Path length: 24 \\<br\\>
194 Return value: 0
195
196
197 Written by \W{https://web.archive.org/web/2018/http://nsis.sourceforge.net/archive/profile.php?userid=78}{djc}
198
199 \# \\<u\\>Acknowledgements & Thanks\\</u\\> \\<br\\>
200 \# Lots of thanks go to \\<b\\>kichik\\</b\\> and \\<b\\>Sunjammer\\</b\\> for spending a lot of time assisting in solving this problem. Also to \\<b\\>brainsucker\\</b\\> for creating the System.dll plug-in in the first place.
201 \# Good Luck!
202
203 \H{dumplogtofile} Dump Content of Log Window to File
204
205 This function will dump the log of the installer (installer details) to a file of your choice.
206
207 To use it, push a file name and call it. It will dump the log to the file specified. For example:
208
209
210 \c GetTempFileName $0
211 \c DetailPrint "Writing log to $0"
212 \c Push $0
213 \c Call DumpLog
214
215 If you're building a \R{intro-unicode}{Unicode installer} you can \cw{!define DumpLog_As_UTF16LE} to output as UTF-16LE or \cw{!define DumpLog_As_UTF16LE "/BOM"} to output as UTF-16LE with a BOM.
216
217 Here is the function:
218
219 \c !define /IfNDef LVM_GETITEMCOUNT 0x1004
220 \c !define /IfNDef LVM_GETITEMTEXTA 0x102D
221 \c !define /IfNDef LVM_GETITEMTEXTW 0x1073
222 \c !if "${NSIS_CHAR_SIZE}" > 1
223 \c !define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTW}
224 \c !else
225 \c !define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTA}
226 \c !endif
227 \c
228 \c Function DumpLog
229 \c Exch $5
230 \c Push $0
231 \c Push $1
232 \c Push $2
233 \c Push $3
234 \c Push $4
235 \c Push $6
236 \c FindWindow $0 "#32770" "" $HWNDPARENT
237 \c GetDlgItem $0 $0 1016
238 \c StrCmp $0 0 exit
239 \c FileOpen $5 $5 "w"
240 \c StrCmp $5 "" exit
241 \c SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
242 \c System::Call '*(&t${NSIS_MAX_STRLEN})p.r3'
243 \c StrCpy $2 0
244 \c System::Call "*(i, i, i, i, i, p, i, i, i) i (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
245 \c loop: StrCmp $2 $6 done
246 \c System::Call "User32::SendMessage(i, i, i, i) i ($0, ${LVM_GETITEMTEXT}, $2, r1)"
247 \c System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
248 \c !ifdef DumpLog_As_UTF16LE
249 \c FileWriteUTF16LE ${DumpLog_As_UTF16LE} $5 "$4$\r$\n"
250 \c !else
251 \c FileWrite $5 "$4$\r$\n" ; Unicode will be translated to ANSI!
252 \c !endif
253 \c IntOp $2 $2 + 1
254 \c Goto loop
255 \c done:
256 \c FileClose $5
257 \c System::Free $1
258 \c System::Free $3
259 \c exit:
260 \c Pop $6
261 \c Pop $4
262 \c Pop $3
263 \c Pop $2
264 \c Pop $1
265 \c Pop $0
266 \c Pop $5
267 \c FunctionEnd
268
269 \H{readreg_multi_sz} How to Read REG_MULTI_SZ Values
270
271 \#{KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthread.php?s=&threadid=131154}{this forum thread}.} This example reads a registry value of the type REG_MULTI_SZ and prints it out. Don't forget to edit where it says "Edit this!" when you test this script. The values must point to a REG_MULTI_SZ value or the example will spit out an error.
272
273 \c OutFile "REG_MULTI_SZ Reader.exe"
274 \c Name "REG_MULTI_SZ Reader"
275 \c ShowInstDetails show
276 \c
277 \c !define HKEY_CLASSES_ROOT 0x80000000
278 \c !define HKEY_CURRENT_USER 0x80000001
279 \c !define HKEY_LOCAL_MACHINE 0x80000002
280 \c !define HKEY_USERS 0x80000003
281 \c !define HKEY_PERFORMANCE_DATA 0x80000004
282 \c !define HKEY_PERFORMANCE_TEXT 0x80000050
283 \c !define HKEY_PERFORMANCE_NLSTEXT 0x80000060
284 \c !define HKEY_CURRENT_CONFIG 0x80000005
285 \c !define HKEY_DYN_DATA 0x80000006
286 \c !define KEY_QUERY_VALUE 0x0001
287 \c !define KEY_ENUMERATE_SUB_KEYS 0x0008
288 \c !define REG_NONE 0
289 \c !define REG_SZ 1
290 \c !define REG_EXPAND_SZ 2
291 \c !define REG_BINARY 3
292 \c !define REG_DWORD 4
293 \c !define REG_DWORD_LITTLE_ENDIAN 4
294 \c !define REG_DWORD_BIG_ENDIAN 5
295 \c !define REG_LINK 6
296 \c !define REG_MULTI_SZ 7
297 \c
298 \c !define RegOpenKeyEx "Advapi32::RegOpenKeyEx(p, t, i, i, *p) i"
299 \c !define RegQueryValueEx "Advapi32::RegQueryValueEx(p, t, p, *i, p, *i) i"
300 \c !define RegCloseKey "Advapi32::RegCloseKeyA(p) i"
301 \c
302 \c ####### Edit this!
303 \c
304 \c !define ROOT_KEY ${HKEY_LOCAL_MACHINE}
305 \c !define SUB_KEY "SYSTEM\CurrentControlSet\Control\Lsa"
306 \c !define VALUE "Security Packages"
307 \c
308 \c ####### Stop editing
309 \c
310 \c Section "Read"
311 \c StrCpy $1 ""
312 \c StrCpy $2 ""
313 \c StrCpy $3 ""
314 \c System::Call "${RegOpenKeyEx}(${ROOT_KEY}, '${SUB_KEY}', \
315 \c 0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, 0 r0) .r3"
316 \c
317 \c StrCmp $3 0 goon
318 \c MessageBox MB_OK|MB_ICONSTOP "Can't open registry key! ($3)"
319 \c Goto done
320 \c goon:
321 \c
322 \c System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, .r1, 0, .r2) .r3"
323 \c
324 \c StrCmp $3 0 read
325 \c MessageBox MB_OK|MB_ICONSTOP "Can't query registry value size! ($3)"
326 \c Goto done
327 \c
328 \c read:
329 \c
330 \c StrCmp $1 ${REG_MULTI_SZ} multisz
331 \c MessageBox MB_OK|MB_ICONSTOP "Registry value not a REG_MULTI_SZ! ($3)"
332 \c Goto done
333 \c
334 \c multisz:
335 \c
336 \c StrCmp $2 0 0 multiszalloc
337 \c MessageBox MB_OK|MB_ICONSTOP "Registry value empty! ($3)"
338 \c Goto done
339 \c
340 \c multiszalloc:
341 \c
342 \c System::Alloc $2
343 \c Pop $1
344 \c
345 \c StrCmp $1 0 0 multiszget
346 \c MessageBox MB_OK|MB_ICONSTOP "Can't allocate enough memory! ($3)"
347 \c Goto done
348 \c
349 \c multiszget:
350 \c
351 \c System::Call "${RegQueryValueEx}(r0, '${VALUE}', 0, n, r1, r2) .r3"
352 \c
353 \c StrCmp $3 0 multiszprocess
354 \c MessageBox MB_OK|MB_ICONSTOP "Can't query registry value data! ($3)"
355 \c Goto done
356 \c
357 \c multiszprocess:
358 \c
359 \c StrCpy $4 $1
360 \c
361 \c loop:
362 \c
363 \c System::Call "*$4(&t${NSIS_MAX_STRLEN} .r3)"
364 \c StrCmp $3 "" done
365 \c DetailPrint $3
366 \c StrLen $5 $3
367 \c !if "${NSIS_CHAR_SIZE}" > 1
368 \c IntOp $5 $5 * ${NSIS_CHAR_SIZE}
369 \c !endif
370 \c IntPtrOp $4 $4 + $5
371 \c IntPtrOp $4 $4 + ${NSIS_CHAR_SIZE}
372 \c Goto loop
373 \c
374 \c done:
375 \c
376 \c System::Free $1
377 \c
378 \c StrCmp $0 0 noClose
379 \c System::Call "${RegCloseKey}(r0)"
380 \c
381 \c noClose:
382 \c
383 \c SectionEnd
384
385 \H{unicode_defines}Predefined Macros for Unicode support
386
387 There are two macros that can help you write scripts that work for both Unicode and ANSI installers. To figure out if the script is being compiled to generate a Unicode installer, use !ifdef to check for NSIS_UNICODE. To see what the size of a character is, use $\{NSIS_CHAR_SIZE\}. It will be 1 for ANSI and 2 for Unicode installers.