AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi lpEnvironment-Parameter bei CreateProcessWithLogonW
Thema durchsuchen
Ansicht
Themen-Optionen

lpEnvironment-Parameter bei CreateProcessWithLogonW

Ein Thema von ringli · begonnen am 30. Jul 2005 · letzter Beitrag vom 2. Aug 2005
Antwort Antwort
Olli
(Gast)

n/a Beiträge
 
#1

Re: lpEnvironment-Parameter bei CreateProcessWithLogonW

  Alt 2. Aug 2005, 10:39
So, habe es jetzt nochmal "mundgerecht" aufgeteilt. Es gibt jetzt eine Wrapperfunktion, der man eine Untermenge der Parameter der ursprünglichen API übergibt. Optional übergibt man auch einen Environment-Block. Das mit dem optional funktioniert natürlich erst ab Delphi 4, wegen dem Default-Parameter.

Delphi-Quellcode:
(******************************************************************************
Function to wrap around the CreateProcessWithLogon() API
******************************************************************************)


function CreateProcessWithLogonWrapper(
  lpUsername: LPCWSTR;
  lpDomain: LPCWSTR;
  lpPassword: LPCWSTR;
  lpApplicationName: LPCWSTR;
  lpCommandLine: LPWSTR;
  dwCreationFlags: DWORD;
  lpEnvironment: LPVOID = nil
  ): Boolean;
var
  sui: STARTUPINFOW;
  pi: PROCESS_INFORMATION;
begin
  Result := False;
  // Fill sui with zeroes
  ZeroMemory(@sui, sizeof(sui));
  // Fill size member
  sui.cb := sizeof(sui);
  // Create process
  if (CreateProcessWithLogonW(
    lpUsername,
    lpDomain, // Domain
    lpPassword,
    LOGON_WITH_PROFILE, // No special options
    lpApplicationName, // Module to execute
    lpCommandLine, // Activates extensions
    dwCreationFlags or CREATE_UNICODE_ENVIRONMENT, // Only these options for now
    lpEnvironment,
    nil, // Use current directory
    sui, // STARTUPINFO
    pi // PROCESS_INFORMATION
    )) then
    Result := True; // Return success
end;

(******************************************************************************
Function to get a copy of the current environment.
The returned pointer MUST BE DESTROYED using the DestroyEnvironmentBlock() API.
******************************************************************************)


function GetCurrentEnvironmentBlock(): LPVOID;
var
  hToken: HANDLE;
begin
  Result := nil;
  // Open process token of current process
  if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY or TOKEN_DUPLICATE, hToken)) then
  try
    // Create copy of current environment block
    if (not CreateEnvironmentBlock(Result, hToken, True)) then
      Result := nil;
  finally
    CloseHandle(hToken); // Close the token of the current process
  end;
end;
CreateProcessWithLogonWrapper() ist einfach der besagte Wrapper. Die Parameter entsprechen denen der Orginal-API insofern vorhanden.

GetCurrentEnvironmentBlock() gibt den Environment-Block des aktuellen Prozesses zurück. Dieser muß danach mit der API DestroyEnvironmentBlock() wieder zerstört werden. Wird nil zurückgegeben, so war der Aufruf nicht erfolgreich.

Anhang und ausführliche Beschreibung zum Code findet sich hier
  Mit Zitat antworten Zitat
Antwort Antwort


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 16:45 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-2025 by Thomas Breitkreuz