AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi TShellExecuteInfo.hProcess<>TProcessInformation.dw ProcessId
Thema durchsuchen
Ansicht
Themen-Optionen

TShellExecuteInfo.hProcess<>TProcessInformation.dw ProcessId

Ein Thema von Meta777 · begonnen am 15. Nov 2005 · letzter Beitrag vom 16. Nov 2005
Antwort Antwort
Seite 1 von 2  1 2      
Meta777

Registriert seit: 8. Sep 2004
Ort: Magdeburg
248 Beiträge
 
Delphi 10 Seattle Enterprise
 
#1

TShellExecuteInfo.hProcess<>TProcessInformation.dw Proc

  Alt 15. Nov 2005, 21:06
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
  Mit Zitat antworten Zitat
Benutzerbild von Flocke
Flocke

Registriert seit: 9. Jun 2005
Ort: Unna
1.172 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 15. Nov 2005, 22:44
Das eine ist ein Prozesshandle (HPROCESS) und das andere eine Prozess-Id (DWORD).

Die Funktion MSDN-Library durchsuchenGetProcessId liefert dir die Id zu einem Handle. Ansonsten liefert dir CreateProcess in der Struktur TProcessInformation aber auch alle Infos, die du benötigst, nämlich sowohl das Handle als auch die Id.
Volker
Besucht meine Garage
Aktuell: RtfLabel 1.3d, PrintToFile 1.4
  Mit Zitat antworten Zitat
Meta777

Registriert seit: 8. Sep 2004
Ort: Magdeburg
248 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 13:22
Hi Flocke,

hab grad im MSDN nachgeschaut und gelesen: http://msdn.microsoft.com/library/de...tprocessid.asp
Zitat:
Requirements
Client Requires Windows "Longhorn" or Windows XP SP1.
Server Requires Windows Server "Longhorn" or Windows Server 2003.
Das würde sicher erklären das GetProcessId nicht in D7 unter W2k verfügbar ist, oder?
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
  Mit Zitat antworten Zitat
NicoDE
(Gast)

n/a Beiträge
 
#4

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 13:56
Zitat von Meta777:
Welche anderen möglichkeiten gibt es die processId anhand des process handles herzubekommen, was dann auch - wenn möglich - unter Win9x läuft?
Soweit ich mich erinnere, mit der offiziellen Win32-API, keine.

Wobei das bei Win9x noch relativ einfach ist (da Process-IDs xor-verschlüsselte Process-Handles sind, siehe: http://www.delphipraxis.net/internal...=212248#212248 ).
  Mit Zitat antworten Zitat
NicoDE
(Gast)

n/a Beiträge
 
#5

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 14:53
Hier eine Version die mit allen Windows-Versionen (32-Bit, inklusive WoW64) funktionieren sollte...
Delphi-Quellcode:
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.
[edit] Kleine Änderung: das Prozess-Handle wird nun unter Win9x mittels GetExitCodeProcess() auf Gültigkeit überprüft [/edit]
  Mit Zitat antworten Zitat
Meta777

Registriert seit: 8. Sep 2004
Ort: Magdeburg
248 Beiträge
 
Delphi 10 Seattle Enterprise
 
#6

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 14:58
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?
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#7

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 15:09
Na, programmiert da wieder jemand zu viel in C:
Code:
GetObsfucator[b]()[/b]
.

aber,. Nico, dürfte ich dich mal auf mein Problem hinweisen: http://www.delphipraxis.net/internal...ct.php?t=68126
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
NicoDE
(Gast)

n/a Beiträge
 
#8

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 15:18
Zitat von Meta777:
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?
Der Quellcode oben ist eine komplette Unit die nur eine Funktion zur Verfügung stellt (GetProcessId) - der Rest passiert automatisch.
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
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#9

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 15:20
Nur mal so aus Neugier: hast du das eben selber alles geschrieben oder hattest du das so rumliegen gehabt?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
NicoDE
(Gast)

n/a Beiträge
 
#10

Re: TShellExecuteInfo.hProcess<>TProcessInformation.dw

  Alt 16. Nov 2005, 15:22
Zitat von Luckie:
Nur mal so aus Neugier: hast du das eben selber alles geschrieben oder hattest du das so rumliegen gehabt?
Typen aus dem DDK kopiert, nach Pascal übersetzt, Logik implementiert und hier gepostet...
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:48 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz