![]() |
Re: delphi / batch kombinieren
Liste der Anhänge anzeigen (Anzahl: 1)
@ichbins
ja, siehe screenshot Grüße Kalus |
Re: delphi / batch kombinieren
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 |
Re: delphi / batch kombinieren
Liste der Anhänge anzeigen (Anzahl: 1)
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. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:25 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