AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

delphi / batch kombinieren

Ein Thema von toredo · begonnen am 26. Apr 2006 · letzter Beitrag vom 27. Apr 2006
Antwort Antwort
Seite 2 von 2     12   
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#11

Re: delphi / batch kombinieren

  Alt 26. Apr 2006, 21:05
@ichbins
ja, siehe screenshot

Grüße
Kalus
Miniaturansicht angehängter Grafiken
env_reg_444.jpg  
Klaus
  Mit Zitat antworten Zitat
toredo

Registriert seit: 6. Apr 2006
Ort: Oberriet
210 Beiträge
 
Delphi 7 Enterprise
 
#12

Re: delphi / batch kombinieren

  Alt 27. Apr 2006, 14:52
hm, wenn ich jetzt aber normal ne variable über start/ausführen/cmd/set a=b definiere dann gibt es keine neue zeichenfolge in der registry, ist denn da ein unterschied wenn man die variable "normal" macht?
und werden die zeichenfokgen auch wieder automatisch gelöscht wenn ich die batch schliesse oder muss ich da noch in batch was schreiben?

n'batch script könnte man natürlich auch erstellen lassen, wäre auch einfahc nur halt unprofessioneller, da man nacher noch mit call auf das script zugreiffen müsste. wäre aber auch keine schlechte lösung.




mfG toredo
Benj Meier
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#13

Re: delphi / batch kombinieren

  Alt 27. Apr 2006, 16:26
Die Funktion die ich mit SetGlobalEnvironment setze, setzt eine globale
Environmnet Variable. Diese ist von jedem cmd Fenster aus
abfragbar. Sie überlebt den reboot.

Um ein Variable nur im activen cmd-Fenster zu haben,
reicht es das API command
SetEnvironmentVariable(PChar(Name), PChar(Value));
auszuführen.

Zu den Parametern gibt es im angehängten pdf File mehr Infos.

Grüße
Klaus

habe ich noch gefunden:
nicht getestet:

Delphi-Quellcode:
unit Environment;

interface

  procedure ActivateEnvironmentVariables;

  function AddGlobalEnvironmentVariable(const Key: string; const Value : string; const now : boolean) : boolean;
  function AddEnvironmentVariable(const Key: string; const Value : string; const now : boolean) : boolean;

  function DelGlobalEnvironmentVariable(const Key: string; const now : boolean) : boolean;
  function DelEnvironmentVariable(const Key: string; const now : boolean) : boolean;

implementation

uses
   Registry, Windows;

const
  GlobalKey = 'System\CurrentControlSet\Control\Session Manager\Environment';
  LocalKey = 'Environment';
  WM_WININICHANGE = $001A;


procedure ActivateEnvironmentVariables;
begin
  SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(PChar('Environment')));
end;

function AddGlobalEnvironmentVariable(const Key: string; const Value : string; const now : boolean) : boolean;
var
  Reg : TRegistry;
  ok : boolean;
begin
  Result := true;
  ok := false;
  try
    Reg := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey(GlobalKey, false) then
    begin
      Reg.WriteString(Key, Value);
      Reg.CloseKey;

      if now then ActivateEnvironmentVariables;
      ok := true;
    end;
    Result := ok;
  except
    Result := false;
  end;
end;

function AddEnvironmentVariable(const Key: string; const Value : string; const now : boolean) : boolean;
var
  Reg : TRegistry;
  ok : boolean;
begin
  Result := true;
  ok := false;
  try
    Reg := TRegistry.Create;
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey(LocalKey, false) then
    begin
      Reg.WriteString(Key, Value);
      Reg.CloseKey;

      if now then ActivateEnvironmentVariables;
      ok := true;
    end;
    Result := ok;
  except
    Result := false;
  end;
  Result := SetEnvironmentVariable(PChar(Key), PChar(Value));
end;

function DelGlobalEnvironmentVariable(const Key: string; const now : boolean) : boolean;
var
  Reg : TRegistry;
  ok : boolean;
begin
  ok := false;
  Result := true;
  try
    Reg := TRegistry.Create;
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey(GlobalKey, false) then
    begin
      Reg.DeleteValue(Key);
      Reg.CloseKey;

      if now then ActivateEnvironmentVariables;
      ok := true;
    end;
    Result := ok;
  except
    Result := false;
  end;
end;

function DelEnvironmentVariable(const Key: string; const now : boolean) : boolean;
var
  Reg : TRegistry;
  ok : boolean;
begin
  ok := false;
  Result := true;
  try
    Reg := TRegistry.Create;
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey(LocalKey, false) then
    begin
      Reg.DeleteValue(Key);
      Reg.CloseKey;

      if now then ActivateEnvironmentVariables;
      ok := true;
    end;
    Result := ok;
  except
    Result := false;
  end;
  Result := SetEnvironmentVariable(PChar(Key), nil);
end;

end.
Angehängte Dateien
Dateityp: pdf setenvironmentvariable_169.pdf (84,0 KB, 3x aufgerufen)
Klaus
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


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 00:44 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