# vim: set expandtab tabstop=4 shiftwidth=4: #
**************************************************************

	Project:	IsAdmin DLL for NSIS
	File:		isadmindll.c

	Author:		Raphael Moll
	Date:		2002/07/22
	Copyright:	2002 (c) Beatware Inc.


	Desc:		Determines if the current (impersonated) user has
				administrator priviledges. Returns 1 to NSIS if
				it does, 0 or a GetLastErorr number to the caller
				if not.

	References:	The core test logic is described here:

	Microsoft Knowledge Base Article - Q118626
	HOWTO: "Determine Whether a Thread Is Running in User Context
	        of Local Administrator Account"
	http://support.microsoft.com/default.aspx?scid=KB;EN-US;q118626&

**************************************************************

Usage in a NSI script:

	; --- Check that the current user has Administrator priviledges
	; Use the isadmindll.dll for this purpose
	; Usage:
	;	call the DLL, then pop $0. If $0 == "1" the user has administrative priviledge.
	
	SetOutPath "$TEMP"
	
	;
	; Need the isadmindll.dll to perform the test
	;
	
	File "isadmindll.dll"
	
	
	;
	; Now test
	;
	
	CallInstDLL "$TEMP\isadmindll.dll" checkIsAdmin
	
	Pop $0 
	; ($0 would be "0" (not admin) or "1" (admin) or some other value on error.

	; DEBUG
	; MessageBox MB_OK|MB_ICONSTOP $0
	

	;
	; Delete the temporary file
	;
	
	Delete /REBOOTOK "$TEMP\isadmindll.dll"
	
	
	;
	; Use the result from the admin test
	;
	
	StrCmp $0 "1" bwAdminContinue	; if is admin, continue
	StrCmp $0 "0" bwNotAdmin		; not admin, notify and abort
	
	
	; bwAdminError:
	
		MessageBox MB_OK|MB_ICONSTOP "The installer could not determine if you have administror priviledges (error $0)."
		Abort ; causes installer to quit immediatly


	bwNotAdmin:

		MessageBox MB_OK|MB_ICONSTOP "You must have administror priviledges to install <product name here>. Please run the installer again in Administrator mode (or shift-right-click the exe and select Run As...)"
		Abort ; causes installer to quit immediatly


	bwAdminContinue:


**************************************************************


//----------------------------------------------------------------
$Id: readme.txt,v 1.1 2002/07/22 23:23:23 ralf Exp $
//----------------------------------------------------------------

