Announcement

Collapse
No announcement yet.

SetForegroundWindow by PID

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Seems to me you did not try very hard.
    PHP Code:
    !include LogicLib.nsh
    Function PSEnum
    ${If} $$MyPid
        DetailPrint 
    "Found $1"
        
    StrCpy $""
    ${EndIf}
    FunctionEnd
     
    Section
    GetFunctionAddress 
    $0 PSEnum
    PS
    ::Enum $0
    SectionEnd 
    IntOp $PostCount $PostCount + 1

    Comment


    • #17
      Maybe, but I didn't focus on that one

      In the meantime I get another solution with wmic... it's slow but seems to work:

      Call_ProcessName:

      StrCpy $2 ""
      searchnamecontinue:
      FindWindow $1 "" "" "" $2
      StrCpy $2 $1
      ${If} $1 P<> 0
      System::Call 'USER32::GetWindowThreadProcessId(p$1,*i0r3)'
      System::Call 'USER32::IsWindowVisible(p $1)i.r4'
      System::Call 'USER32::GetWindowText(p $1, t ""r5, i ${NSIS_MAX_STRLEN})'
      ${If} $5 != ""
      ${AndIf} $4 <> 0
      nsExec::ExecToStack "wmic process where $\"name like '$ProcessID' and ProcessID like '$3'$\" get processid
      /format:$\"$PLUGINSDIR\${XlsSheet}$\""
      Pop $0
      Pop $7
      ${StrRep} $7 $7 "processid=" ""
      Push ' $7 '
      Call Trim
      Pop $8 ;$8 now contains the trimmed string.
      ${If} $3 == $8
      ;MessageBox MB_OK "Erkannt! PID: $3"
      System::Call 'USER32::SetForegroundWindow(p$1)'
      System::Call 'USER32::SwitchToThisWindow(p$1,i1)'
      ${EndIf}
      ${EndIf}
      Goto searchnamecontinue
      ${EndIf}
      Goto EndSearch

      Comment


      • #18
        OK, with WMIC as for prcessname-based call and some other improvements here is my final solution as a ready-to-use binary download:

        https://github.com/Dragodraki/BringExeToFront

        Hope, that helps somebody else in the future.

        Comment

        Working...
        X