{I+=codeWee;}
[NSIS] NSIS : How to set shorcut icon for "Run as Administrator"
!ifndef IPersistFile
!define IPersistFile {0000010b-0000-0000-c000-000000000046}
!endif
!ifndef CLSID_ShellLink
!define CLSID_ShellLink {00021401-0000-0000-C000-000000000046}
!define IID_IShellLinkA {000214EE-0000-0000-C000-000000000046}
!define IID_IShellLinkW {000214F9-0000-0000-C000-000000000046}
!define IShellLinkDataList {45e2b4ae-b1c3-11d0-b92f-00a0c90312e1}
	!ifdef NSIS_UNICODE
	!define IID_IShellLink ${IID_IShellLinkW}
	!else
	!define IID_IShellLink ${IID_IShellLinkA}
	!endif
!endif
 
Function ShellLinkSetRunAs
	System::Store S
	pop $9
	System::Call "ole32::CoCreateInstance(g'${CLSID_ShellLink}',i0,i1,g'${IID_IShellLink}',*i.r1)i.r0"
	${If} $0 = 0
		System::Call "$1->0(g'${IPersistFile}',*i.r2)i.r0" ;QI
		${If} $0 = 0
			System::Call "$2->5(w '$9',i 0)i.r0" ;Load
			${If} $0 = 0
				System::Call "$1->0(g'${IShellLinkDataList}',*i.r3)i.r0" ;QI
				${If} $0 = 0
					System::Call "$3->6(*i.r4)i.r0" ;GetFlags
					${If} $0 = 0
						System::Call "$3->7(i $4|0x2000)i.r0" ;SetFlags ;SLDF_RUNAS_USER
						${If} $0 = 0
							System::Call "$2->6(w '$9',i1)i.r0" ;Save
						${EndIf}
					${EndIf}
					System::Call "$3->2()" ;Release
				${EndIf}
			System::Call "$2->2()" ;Release
			${EndIf}
		${EndIf}
		System::Call "$1->2()" ;Release
	${EndIf}
	push $0
	System::Store L
FunctionEnd



Section "test"

...
	CreateDirectory "$SMPROGRAMS\abc"
	CreateShortcut "$SMPROGRAMS\abc\mylink.lnk" "$INSTDIR\myprogram.exe"  "" "$INSTDIR\myicon.ico" 0

	push "$SMPROGRAMS\abc\mylink.lnk"
	call ShellLinkSetRunAs
	pop $0

...

SectionEnd

HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.