![]() |
TShellExecuteInfo.hProcess<>TProcessInformation.dw Proc
Huhu DPler,
Bin grad dabei eine bestehende ExecAndWait Function um den Parameter "MoniIdx" zu erweitern. Die ExecAndWait benutzt ShellExecuteEx(SEInfo) zum ausführen. Ich will nun also das Haupt-Fenster des gestarteten proggis auf einen anderen Monitor setzen (moniIdx)! Nun hab ich aber das Problem das ich mit SEInfo.hProcess nicht auf das Haupt-Formular zugreifen kann - hab versucht mit EnumWindows die Prozess-Id mit GetWindowThreadProcessId(hWnd, @PId) herauszufinden und zu vergleichen, aber das Fenster hat eine andere Prozeß-Id als SEInfo.hProcess :? Allerdings, wie der Titel erahnen läßt, funktioniert das ermitteln des Haupt-Fensters mit TProcessInformation.dwProcessId! TProcessInformation wird jedoch mit CreateProcess() verwendet. Wo ist also der Unterschied :?: Und wie kann ich das Haupt-Fenster des gestarteten proggis mittels SEInfo ermitteln :?: Danke & Gottes Segen euch |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Das eine ist ein Prozesshandle (HPROCESS) und das andere eine Prozess-Id (DWORD).
Die Funktion ![]() |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Hi Flocke,
hab grad im MSDN nachgeschaut und gelesen: ![]() Zitat:
Welche anderen möglichkeiten gibt es die processId anhand des process handles herzubekommen, was dann auch - wenn möglich - unter Win9x läuft? Danke für deine Hilfe |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Zitat:
Wobei das bei Win9x noch relativ einfach ist (da Process-IDs xor-verschlüsselte Process-Handles sind, siehe: ![]() |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Hier eine Version die mit allen Windows-Versionen (32-Bit, inklusive WoW64) funktionieren sollte...
Delphi-Quellcode:
[edit] Kleine Änderung: das Prozess-Handle wird nun unter Win9x mittels GetExitCodeProcess() auf Gültigkeit überprüft [/edit]
unit ProcessUtils {platform};
interface uses Windows; function GetProcessId(Process: THandle): DWORD stdcall; implementation {$ALIGN 8} {$MINENUMSIZE 4} {$WRITEABLECONST ON} // // Windows 9x // function GetObsfucator(): DWORD; asm call GetCurrentThreadId push eax call GetCurrentProcessId xor edx, edx xor eax, fs:[edx + 30h] pop ecx xor ecx, eax sub ecx, fs:[edx + 18h] add ecx, 08h jecxz @@done add ecx, 08h jecxz @@done xor eax, eax @@done: end; // // Windows NT // type PProcessInfoClass = ^TProcessInfoClass; TProcessInfoClass = ( ProcessBasicInformation, ProcessQuotaLimits, ProcessIoCounters, ProcessVmCounters, ProcessTimes, ProcessBasePriority, ProcessRaisePriority, ProcessDebugPort, ProcessExceptionPort, ProcessAccessToken, ProcessLdtInformation, ProcessLdtSize, ProcessDefaultHardErrorMode, ProcessIoPortHandlers, ProcessPooledUsageAndLimits, ProcessWorkingSetWatch, ProcessUserModeIOPL, ProcessEnableAlignmentFaultFixup, ProcessPriorityClass, ProcessWx86Information, ProcessHandleCount, ProcessAffinityMask, ProcessPriorityBoost, ProcessDeviceMap, ProcessSessionInformation, ProcessForegroundInformation, ProcessWow64Information, ProcessImageFileName, ProcessLUIDDeviceMapsEnabled, ProcessBreakOnTermination, ProcessDebugObjectHandle, ProcessDebugFlags, ProcessHandleTracing, ProcessIoPriority, ProcessExecuteFlags, ProcessResourceManagement, ProcessCookie, ProcessImageInformation, MaxProcessInfoClass ); type PProcessBasicInformation = ^TProcessBasicInformation; TProcessBasicInformation = record ExitStatus : LongInt; PebBaseAddress : Pointer; AffinityMask : Cardinal; BasePriority : LongInt; UniqueProcessId : Cardinal; InheritedFromUniqueProcessId: Cardinal; end; function NtQueryInformationProcess(ProcessHandle: THandle; ProcessInformationClass: TProcessInfoClass; ProcessInformation: Pointer; ProcessInformationLength: ULONG; ReturnLength: PULONG): LongInt stdcall; type TFNNtQueryInformationProcess = function(ProcessHandle: THandle; ProcessInformationClass: TProcessInfoClass; ProcessInformation: Pointer; ProcessInformationLength: ULONG; ReturnLength: PULONG): LongInt stdcall; const FNNtQueryInformationProcess: TFNNtQueryInformationProcess = nil; begin if not Assigned(FNNtQueryInformationProcess) then FNNtQueryInformationProcess := TFNNtQueryInformationProcess( GetProcAddress(GetModuleHandle('ntdll.dll'), 'NtQueryInformationProcess')); if not Assigned(FNNtQueryInformationProcess) then Result := LongInt($C0000002) // STATUS_NOT_IMPLEMENTED else Result := FNNtQueryInformationProcess(ProcessHandle, ProcessBasicInformation, ProcessInformation, ProcessInformationLength, ReturnLength); end; // // Wrapper // function GetProcessId(Process: THandle): DWORD stdcall; type TFNGetProcessId = function(Process: THandle): DWORD stdcall; const FNGetProcessId: TFNGetProcessId = nil; var ExitCode: DWORD; BasicInformation: TProcessBasicInformation; begin // Check for 'CurrentProcess' handle if Process = GetCurrentProcess() then begin Result := GetCurrentProcessId(); Exit; end; // Check for exported Win32 API... if not Assigned(FNGetProcessId) then FNGetProcessId := TFNGetProcessId( GetProcAddress(GetModuleHandle(kernel32), 'GetProcessId')); if Assigned(FNGetProcessId) then Result := FNGetProcessId(Process) else // Try native versions if (DWORD(GetVersion()) > DWORD($80000000)) then begin // Win9x if GetExitCodeProcess(Process, ExitCode) then // validate handle Result := Process xor GetObsfucator() else Result := 0; end else // WinNT if NtQueryInformationProcess(Process, ProcessBasicInformation, @BasicInformation, SizeOf(TProcessBasicInformation), nil) >= 0 then Result := BasicInformation.UniqueProcessId else Result := 0; end; end. |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Kuhl, Danke Nico!!!!!!
Gottes Segen Edit: Diese GetObsfucator ruft ja GetCurrentProcessId auf, ich brauche aber die ProcessId des mit ShellExecuteEx() gestarteten Program? Ich hab den code nur überflogen, vielleicht muss das ja so sein? |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Na, programmiert da wieder jemand zu viel in C:
Code:
. :mrgreen:
GetObsfucator[b]()[/b]
aber,. Nico, dürfte ich dich mal auf mein Problem hinweisen: ![]() |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Zitat:
Es fehlt mir die Zeit um auf Details einzugehen. Deshalb nur kurz: der sogenannte 'Obsfucator' ist ein Xor-Schlüssel mit dem unter Win9x Process-Handles in Process-IDs 'übersetzt' werden können... edit@luckie: a) das ist gültiges Pascal (Delphi Language) b) wenn ich zuviel Zeit habe ;) |
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Nur mal so aus Neugier: hast du das eben selber alles geschrieben :shock: oder hattest du das so rumliegen gehabt?
|
Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:16 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz