Get installer filename: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
(added $EXEPATH)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== METHOD 1: USING THE WINDOWS API (RECOMMENDED) ==
{{PageAuthor|Afrow UK}}
 
== METHOD 1: USING THE WINDOWS API (BEST) ==
Upgrade to NSIS 2.26 or above and use '''$EXEPATH'''.
 
=== Usage ===
<highlight-nsis>
DetailPrint $EXEPATH
</highlight-nsis>
 
== METHOD 2: USING THE WINDOWS API (RECOMMENDED FOR OLD VERSIONS) ==
=== The Script ===
=== The Script ===
<highlight-nsis>
<highlight-nsis>
Line 5: Line 15:
;$R0 will contain the installer filename
;$R0 will contain the installer filename
</highlight-nsis>
</highlight-nsis>
== METHOD 2: GET FROM THE COMMAND LINE ==
 
== METHOD 3: GET FROM THE COMMAND LINE ==


'''Note:''' If the installer is executed using the console, the command line might not contain the current folder or the .exe extension.
'''Note:''' If the installer is executed using the console, the command line might not contain the current folder or the .exe extension.
Line 58: Line 69:
</highlight-nsis>
</highlight-nsis>


Page author: [[User:Afrow UK|Afrow UK]]
[[Category:Disk, Path & File Functions]]

Latest revision as of 21:34, 19 April 2007

Author: Afrow UK (talk, contrib)


METHOD 1: USING THE WINDOWS API (BEST)

Upgrade to NSIS 2.26 or above and use $EXEPATH.

Usage

DetailPrint $EXEPATH

METHOD 2: USING THE WINDOWS API (RECOMMENDED FOR OLD VERSIONS)

The Script

System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
;$R0 will contain the installer filename

METHOD 3: GET FROM THE COMMAND LINE

Note: If the installer is executed using the console, the command line might not contain the current folder or the .exe extension.

Usage

Call GetAppName
Pop $R0 ;Installer filename

The Function

Function GetAppName
 
  Push $R0
  Push $R1
  Push $R2
  Push $R3
 
  StrCpy $R2 1
  StrLen $R3 $CMDLINE
 
  ;Check for quote or space
  StrCpy $R0 $CMDLINE $R2
  StrCmp $R0 '"' 0 +3
    StrCpy $R1 '"'
    Goto loop
  StrCpy $R1 " "
 
  loop:
    IntOp $R2 $R2 + 1
    StrCpy $R0 $CMDLINE 1 $R2
    StrCmp $R0 $R1 get
    StrCmp $R2 $R3 get
    Goto loop
 
  get:
    StrCmp $R1 '"' 0 +4
      IntOp $R2 $R2 - 1
      StrCpy $R0 $CMDLINE $R2 1
      Goto exit
    StrCpy $R0 $CMDLINE $R2
 
  exit:
 
  Pop $R3
  Pop $R2
  Pop $R1
  Exch $R0
 
FunctionEnd