AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) gelöst: CreateProcess und "Environment-Block"
Thema durchsuchen
Ansicht
Themen-Optionen

gelöst: CreateProcess und "Environment-Block"

Ein Thema von TSHObject · begonnen am 10. Jun 2025 · letzter Beitrag vom 11. Jun 2025
 
TSHObject

Registriert seit: 29. Apr 2006
Ort: Schweiz
15 Beiträge
 
Delphi 12 Athens
 
#4

AW: CreateProcess und "Environment-Block"

  Alt 11. Jun 2025, 06:19
Vielen Dank für eueren Input.

Meine Lösung sieht nun so aus:

Delphi-Quellcode:
function SetEnvironmentsVars(const Vars: TStrings): Boolean;
var
i: integer;
_line:string;
_Name:string;
_Value:string;
_EqualsPos:integer;
_DoublePointPos:integer;
_prefix:string;
_ErrorMsg:string;
_ProblemCount:integer;
begin
  _ProblemCount:=0;
  for i := 0 to Vars.Count - 1 do begin
    _line := Vars[i];
    _EqualsPos := Pos('=', _line);
    if _EqualsPos=-1 then begin
      inc(_ProblemCount);
      _ErrorMsg:=format('SetEnvironmentsVars: The environment statement <%s> does not contain the character "=". Ignore this line.',[_line]);
      OutputDebugString(PChar(_ErrorMsg));
      continue;
    end;

    if _EqualsPos=1 then begin
      _DoublePointPos := Pos(':', _line);
      _prefix:=Copy(_line,1,_DoublePointPos);
      delete(_Line,1,_DoublePointPos);
    end
    else _prefix:='';

    _Name := _prefix+_Line.Substring(0,_EqualsPos-1);
    _Value := _Line.Substring(_EqualsPos);
    if not SetEnvironmentVariable(PChar(_Name), PChar(_Value)) then begin
      inc(_ProblemCount);
      _ErrorMsg:=format('SetEnvironmentsVars: Could not set environment variable <%s=%s>. <%s>.',[_Name,_Value,SysErrorMessage(GetLastError)]);
    end;
  end;
  result:=(_ProblemCount=0);
end;
  Mit Zitat antworten Zitat
 


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 03:55 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