-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsexec.nsh
67 lines (53 loc) · 1.81 KB
/
psexec.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
; Source: https://nsis.sourceforge.io/PowerShell_support
; I modified the "PowerShellExecFileMacro" "PowerShellExecFileLogMacro" macros slightly to support parameters
!ifndef PSEXEC_INCLUDED
!define PSEXEC_INCLUDED
!macro PowerShellExecMacro PSCommand
InitPluginsDir
;Save command in a temp file
Push $R1
FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w
FileWrite $R1 "${PSCommand}"
FileClose $R1
Pop $R1
!insertmacro PowerShellExecFileMacro "$PLUGINSDIR\tempfile.ps1"
!macroend
!macro PowerShellExecLogMacro PSCommand
InitPluginsDir
;Save command in a temp file
Push $R1
FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w
FileWrite $R1 "${PSCommand}"
FileClose $R1
Pop $R1
!insertmacro PowerShellExecFileLogMacro "$PLUGINSDIR\tempfile.ps1"
!macroend
!macro PowerShellExecFileMacro PSFileandParams
!define PSExecID ${__LINE__}
Push $R0
nsExec::ExecToStack 'powershell -inputformat none -ExecutionPolicy RemoteSigned -File ${PSFileandParams} '
Pop $R0 ;return value is first on stack
;script output is second on stack, leave on top of it
IntCmp $R0 0 finish_${PSExecID}
SetErrorLevel 2
finish_${PSExecID}:
Exch ;now $R0 on top of stack, followed by script output
Pop $R0
!undef PSExecID
!macroend
!macro PowerShellExecFileLogMacro PSFileandParams
!define PSExecID ${__LINE__}
Push $R0
nsExec::ExecToLog 'powershell -inputformat none -ExecutionPolicy RemoteSigned -File ${PSFileandParams} '
Pop $R0 ;return value is on stack
IntCmp $R0 0 finish_${PSExecID}
SetErrorLevel 2
finish_${PSExecID}:
Pop $R0
!undef PSExecID
!macroend
!define PowerShellExec `!insertmacro PowerShellExecMacro`
!define PowerShellExecLog `!insertmacro PowerShellExecLogMacro`
!define PowerShellExecFile `!insertmacro PowerShellExecFileMacro`
!define PowerShellExecFileLog `!insertmacro PowerShellExecFileLogMacro`
!endif