English
Source / code snippets

Fensterhandle Prozessname

 

Georg
Teles
Simple detect one Fensterhandle anhand the Prozessnamens or. PID
Declare exe_$, hwnd_&
' from EXE-names Window-lever ermittlen
exe_$ = SubStr$( Par$( 0 ), -1, "\\" )
'exe_$ = "irgendeine.exe"
' DEF
Def CreateToolhelp32Snapshot(2) ! "Kernel32", "CreateToolhelp32Snapshot"
Def Process32First(2)           ! "Kernel32", "Process32First"
Def Process32Next(2)            ! "Kernel32", "Process32Next"
Def CloseHandle(1)              ! "Kernel32", "CloseHandle"
Def EnumWindows(2)              ! "User32", "EnumWindows"
Def GetWindowThreadProcessId(2) ! "User32", "GetWindowThreadProcessId"
' Constant
Def &TH32CS_SNAPPROCESS $2
'

Proc exe2lever

    Parameters prozess$
    Declare hcTH32S&, out#, pid&
    Clear pid&
    Struct PROCESSENTRY32 = dwSize&, cntUsage&, th32ProcessID&, th32DefaultHeapID&, th32ModuleID&, Threads&, th32ParentProcessID&, pcPriClassBase&, dwFlags&, szExeFile$( 260 )
    Dim out#, PROCESSENTRY32
    out#.dwSize& = SizeOf( out# )
    hcTH32S& = CreateToolhelp32Snapshot( &TH32CS_SNAPPROCESS, 0 )

    If hcTH32S&

        If Process32First( hcTH32S&, out# )

            Repeat

                If Lower$( out#.szExeFile$ ) = Lower$( prozess$ )

                    ' PID of EXE-names read
                    pid& = out#.th32ProcessID&

                EndIf

            Until ( pid& = hardship( 0 ) ) | ( Process32Next( hcTH32S&, out# ) = 0 )

            ' All windows go stampeded To hits with the sought PID debarked becomes
            ' though is it the first hits ! d.H. if EXE multiple runs, is this the Result the first Treffers !
            EnumWindows( ProcAddr( "winproc", 2 ), pid& )

        EndIf

        CloseHandle( hcTH32S& )

    EndIf

    Dispose out#
    Return 0

ENDPROC

' EnumWindowsProc

Proc winproc

    Parameters hWnd&, lParam&
    Declare lpdwProcessID&
    Clear lpdwProcessID&
    GetWindowThreadProcessId( hWnd&, addr( lpdwProcessID& ) )

    Ifnot hardship( lpdwProcessID& = lparam& )

        hwnd_& = hwnd&'----------------------------------------------| GLOBALE Variable « hwnd_& » !
        return 0

    EndIf

    return 1

ENDPROC

' Hauptprogramm
CLS
exe2lever( exe_$ )
' Window-lever & Window-Text the sought Prozesses
print hwnd_&;" - ";GetText$( hwnd_& )
Waitinput

( deference, ausbaubar ! )
 
TC-Programming [...] 
XProfan 8.0 - 10.0 - X2 - X3 - X4

01/14/15  
 




Michael
W.
Ifnot hardship()
 
XProfan X3
System: Windows 8/10, XProfan X4
Programmieren, das spannendste Detektivspiel der Welt.
01/14/15  
 



Michael W. (14.01.15)
Ifnot hardship()


even:

Ifnot hardship( lpdwProcessID& = lparam& )

ergo already in the Klammer ausgewertet, then by hardship obs 0 is, then ifs 0 is, not.

from the Logik since Gibts there well but nothing dran auszusetzen, is hold spicy words.

The computer had anyway with

If lpdwProcessID& = lparam&

less To do. ^^
 
01/14/15  
 




Georg
Teles
exactly. in the original Source ( Delphi ) stood it so similar, found I a little witty.
therefore too so übernommen with the Info «( deference, ausbaubar !
( or would Baustellenquellcode sooner fit )

not sure whether one in Delphi it rather make could but here The WinProc original

fountain: [...] 
 
XProfan X2
TC-Programming [...] 
XProfan 8.0 - 10.0 - X2 - X3 - X4

01/14/15  
 



Achso, there go 2 items Done - once the Returnwert staid - thatswhy the hardship(result) settle and thereafter again look whether windowHandle staid go should. from Pascalsicht ergibts sense.

In C or Java wäres sichtbarer...

result=ProcessID!=LParam

if (!result) ...

but too in Delphi/Pascal can well...

result:= processid<>Lparam

but the know Roland rather.
 
01/14/15  
 




RGH
Yes, too there standing Result for Return Value the procedure. (alternatively can but still How former To Turbo-Pascal-times instead of "Result" whom Prozedurnamen write.)

Greeting
Roland
 
XProfan X2
Intel Duo E8400 3,0 GHz / 4 GB RAM / 1000 GB HDD - ATI Radeon HD 4770 512 MB - Windows 7 Home Premium 32Bit - XProfan X4
01/14/15  
 




Georg
Teles
Aah understand,

The Variable Result is a manner Return with the Difference, that Pascal The command To End; abarbeitet & WindowHandle is here a Globale Variable
 
XProfan X2
TC-Programming [...] 
XProfan 8.0 - 10.0 - X2 - X3 - X4

01/14/15  
 




Georg
Teles
Nabend,

work straight in a Tool, with the one Program launched becomes (here cmd.exe), using and subsequently terminiert.

circa exakt the launched Program to find ergo thereafter which FensterHandle To steer, without on Findindow access (there cmd.exe Yes number of times walk can and herewith impossible becomes, that one other cmd.exe Window gesteuert becomes), becomes The function WinProc using.
Def CreateToolhelp32Snapshot(2) ! "KERNEL32", "CreateToolhelp32Snapshot"
Def Process32First(2)           ! "KERNEL32", "Process32First"
Def Process32Next(2)            ! "KERNEL32", "Process32Next"
Def CloseHandle(1)              ! "KERNEL32", "CloseHandle"
Def EnumWindows(2)              ! "USER32", "EnumWindows"
Def GetWindowThreadProcessId(2) ! "USER32", "GetWindowThreadProcessId"
Def &TH32CS_SNAPPROCESS $2
Def GetProcessId(1)             ! "KERNEL32", "GetProcessId"
Def CreateProcess(10)           ! "KERNEL32","CreateProcessA"
Def GetExitCodeProcess(2)       ! "KERNEL32","GetExitCodeProcess"
Def TerminateProcess(2)         ! "KERNEL32","TerminateProcess"
Declare Command#,StartupInfo#,ProcessInfo#,ExitCode#
Declare Terminate&,Start&,Program$
Declare lst&
Declare fwnd&, pwnd&, phnd&, gpid&
Window 1280,0-1200,800
Programm$ = "cmd.exe"
phnd& = createProcessExe(Program$)
Print "Create Process: "+Str $(phnd&)+" (0 = Fehler; >0 = Process lever)"
Print
Sleep 500
fwnd& = FindWindow("C:\windows\SYSTEM32\cmd.exe")
gpid& = GetProcessID(phnd&)
exe2whandle("cmd.exe")
Print "Gesuchtes Hanlde (probably!):"
Print "FindWindow    / fwnd& (WindowHandle):   ";Str $(fwnd&)
Print
Print "Ergebnis:"
Print "createProzess / phnd& (Process lever): ";Str $(phnd&)
Print "createProzess / gpid& (ProcessID):      ";Str $(gpid&)
Print "createProzess / pwnd& (WindowHandle):   ";Str $(pwnd&)
Print
waitinput
Print "Prozess exits: "+Str $(KillProcess(phnd&))+" (1 = OK; 0 = Error)"
waitinput

Proc exe2whandle

    Parameters prozess$
    Declare hcTH32S&, out#, pid&
    Clear pid&
    Struct PROCESSENTRY32 = dwSize&, cntUsage&, th32ProcessID&, th32DefaultHeapID&, th32ModuleID&, Threads&, th32ParentProcessID&, pcPriClassBase&, dwFlags&, szExeFile$( 260 )
    Dim out#, PROCESSENTRY32
    out#.dwSize& = SizeOf(out#)
    hcTH32S& = CreateToolhelp32Snapshot(&TH32CS_SNAPPROCESS,0)

    If hcTH32S&

        If Process32First(hcTH32S&,out#)

            Repeat

                If Lower$(out#.szExeFile$) = Lower$(prozess$)

                    ' PID of EXE-names read
                    pid& = out#.th32ProcessID&

                EndIf

            Until (pid& = hardship(0)) | (Process32Next(hcTH32S&,out#)=0)

            ' All windows go stampeded To hits with the sought PID debarked becomes
            ' though is it the first hits ! d.H. if EXE multiple runs, is this the Result the first Treffers !
            EnumWindows(ProcAddr("winproc",2),pid&)

        EndIf

        CloseHandle(hcTH32S&)

    EndIf

    Dispose out#
    Return 0

ENDPROC

Proc winproc

    Parameters hWnd&, lParam&
    Declare lpdwProcessID&
    Clear lpdwProcessID&
    GetWindowThreadProcessId(hWnd&,addr(lpdwProcessID&))

    If (lpdwProcessID& = lparam&)

        If lpdwProcessID& = gpid&

            AddStrings(lst&,Str $(hwnd&)+"|"+Str $(lpdwProcessID&))
            pwnd& = hwnd&'----------------------------------------------| pwnd& is here global !
            return 0

        EndIf

    EndIf

    return 1

ENDPROC

Proc createProcessExe

    Parameters command$
    Declare handle&
    Dim Command#,(Len(command$)+1)
    Dim StartupInfo#,68
    Clear startupinfo#
    Long StartupInfo#,0=68
    Dim ProcessInfo#,16
    Clear ProcessInfo#
    String Command#,0 = command$
    CreateProcess(0,Command#,0,0,0,0,0,0,StartupInfo#,ProcessInfo#)
    Let handle& = Long(ProcessInfo#,0)
    Dispose Command#
    Dispose StartupInfo#
    Dispose ProcessInfo#
    Return handle&

ENDPROC

Proc KillProcess

    Parameters hprocess&
    Dim exitcode#,4
    GetExitCodeProcess(hprocess&,exitcode#)
    TerminateProcess(hprocess&,Long(exitcode#,0))
    Dispose exitcode#

ENDPROC


EDIT:
near It's all right still plainer with WinExec
Def CreateToolhelp32Snapshot(2) ! "KERNEL32", "CreateToolhelp32Snapshot"
Def Process32First(2)           ! "KERNEL32", "Process32First"
Def Process32Next(2)            ! "KERNEL32", "Process32Next"
Def CloseHandle(1)              ! "KERNEL32", "CloseHandle"
Def EnumWindows(2)              ! "USER32", "EnumWindows"
Def GetWindowThreadProcessId(2) ! "USER32", "GetWindowThreadProcessId"
Def &TH32CS_SNAPPROCESS $2
Declare lst&, Program$
Declare fwnd&, pwnd&, phnd&, gpid&
Window 1280,0-1200,800
Programm$ = "cmd.exe"
gpid& = WinExec(Program$,1)
Print "PID WinExec: "+Str $(gpid&)+" (0 = Fehler; >0 = PID)"
Print
Sleep 100
fwnd& = FindWindow("C:\windows\SYSTEM32\cmd.exe")
exe2whandle("cmd.exe")
Print "Gesuchtes Hanlde (probably!):"
Print "FindWindow    / fwnd& (WindowHandle):   ";Str $(fwnd&)
Print
Print "Ergebnis:"
Print "createProzess / gpid& (ProcessID):      ";Str $(gpid&)
Print "createProzess / pwnd& (WindowHandle):   ";Str $(pwnd&)
Print
waitinput
Print "Prozess exits: "+Str $(Process("Kill", gpid&, 0))+" (1 = OK; 0 = Error)"
waitinput

Proc exe2whandle

    Parameters prozess$
    Declare hcTH32S&, out#, pid&
    Clear pid&
    Struct PROCESSENTRY32 = dwSize&, cntUsage&, th32ProcessID&, th32DefaultHeapID&, th32ModuleID&, Threads&, th32ParentProcessID&, pcPriClassBase&, dwFlags&, szExeFile$( 260 )
    Dim out#, PROCESSENTRY32
    out#.dwSize& = SizeOf(out#)
    hcTH32S& = CreateToolhelp32Snapshot(&TH32CS_SNAPPROCESS,0)

    If hcTH32S&

        If Process32First(hcTH32S&,out#)

            Repeat

                If Lower$(out#.szExeFile$) = Lower$(prozess$)

                    ' PID of EXE-names read
                    pid& = out#.th32ProcessID&

                EndIf

            Until (pid& = hardship(0)) | (Process32Next(hcTH32S&,out#)=0)

            ' All windows go stampeded To hits with the sought PID debarked becomes
            ' though is it the first hits ! d.H. if EXE multiple runs, is this the Result the first Treffers !
            EnumWindows(ProcAddr("winproc",2),pid&)

        EndIf

        CloseHandle(hcTH32S&)

    EndIf

    Dispose out#
    Return 0

ENDPROC

Proc winproc

    Parameters hWnd&, lParam&
    Declare lpdwProcessID&
    Clear lpdwProcessID&
    GetWindowThreadProcessId(hWnd&,addr(lpdwProcessID&))

    If (lpdwProcessID& = lparam&)

        If lpdwProcessID& = gpid&

            AddStrings(lst&,Str $(hwnd&)+"|"+Str $(lpdwProcessID&))
            pwnd& = hwnd&'----------------------------------------------| pwnd& is here global !
            return 0

        EndIf

    EndIf

    return 1

ENDPROC


Regards
 
TC-Programming [...] 
XProfan 8.0 - 10.0 - X2 - X3 - X4

vor 26 Tagen  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

11.154 Views

Untitledvor 0 min.
Gast.0815Vorgestern (20:24)
RudiB. vor 21 Tagen
ByteAttack vor 21 Tagen
Roland Schäffer vor 21 Tagen
More...

Themeninformationen



Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie