NSIS调用dll函数

时间:2015-02-27 05:44:36

标签: nsis

请帮帮我。我有一个小脚本:

*!include Library.nsh
!include nsDialogs.nsh
!include LogicLib.nsh
!include WordFunc.nsh
SetPluginUnload alwaysoff
Outfile "Impersonate.exe"



# create a default section.
Section
System::Call "wtsapi32::WTSGetActiveConsoleSessionId() i .r0" 
MessageBox MB_OK "Ative session: $0"// Here i got error in $0

 System::Call 'wtsapi32::WTSEnumerateSessionsA(i 0, i 0, i 1, *i .r0, *i .r1) i .r2'
${If} $2 != 0
    ${For} $R2 1 $1
        System::Call "*$0(i .r3, &t1024 .r4, i .r5)"
        DetailPrint "a = $0, $3, $4, $5"//Here i got spoild data
    ${Next}
    System::Call 'wtsapi32::WTSFreeMemory(i r0)'
${EndIf}
SetPluginUnload manual
System::Free 0
SectionEnd*

我的剧本有什么问题?如何正确枚举结构类型的数据?

感谢。

1 个答案:

答案 0 :(得分:1)

WTSGetActiveConsoleSessionId实际上在kernel32中。 WTS_SESSION_INFO中的pWinStationName是指向字符串的指针,您必须在循环中移动/指针才能访问后续项目:

!include LogicLib.nsh
!define WTS_CURRENT_SERVER 0
!if "${NSIS_PTR_SIZE}" <= 4
!define STRUCTSIZE_WTS_SESSION_INFO 12
!endif

Section
System::Call "KERNEL32::WTSGetActiveConsoleSessionId()i.r0" 
DetailPrint WTSGetActiveConsoleSessionId=$0

System::Call 'wtsapi32::WTSEnumerateSessions(i ${WTS_CURRENT_SERVER}, i 0, i 1, *i .r0, *i .r1)i.r2'
DetailPrint "WTSEnumerateSessions returned $2, count=$1"
${If} $2 <> 0
    StrCpy $R2 0
    ${DoWhile} $R2 U< $1
        IntOp $2 ${STRUCTSIZE_WTS_SESSION_INFO} * $R2
        !if "${NSIS_PTR_SIZE}" <= 4
        IntOp $2 $0 + $2
        !else
        !error TODO
        !endif
        System::Call "*$2(i .r3, t.r4, i .r5)"
        DetailPrint "#$R2 PWTS_SESSION_INFO@$2: sess=$3, winsta=$4, state=$5"
        IntOp $R2 $R2 + 1
    ${Loop}
    System::Call 'wtsapi32::WTSFreeMemory(i r0)'
${EndIf}
System::Free 0
SectionEnd