Systemvariablen schreiben geht nicht!
-
Hallo Leute,
ich brauche für ein Programm ein Systemvariable welche ich versuche zu schreiben, aber leider geht es nicht!
Ich habe es schon mit
_putenv("TEST=C:/Test");
und auch schon mit
_putenv_s("TEST", "C:/Test");
probiert, aber beide male kann ich die Variable nicht finden (also in der cmd "set" eintippen listet alle Variablen auf)! Wenn ich es händisch mache also in der Konsole
set TEST=C:/Test
eingebe, funktioniert es!
Was kann da falsch gelaufen sein?
Ach ja, die
#include <stdlib.h>
die habe ich natürlich auch eingebunden und ich arbeite in VS2012...
-
Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x und C++11) in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
http://msdn.microsoft.com/en-us/library/eyw7eyfw(v=vs.120).aspx
_putenv_s and _wputenv_s affect only the environment that is local to the current process; you cannot use them to modify the command-level environment.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx
To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.
-
EinGast schrieb:
http://msdn.microsoft.com/en-us/library/eyw7eyfw(v=vs.120).aspx
_putenv_s and _wputenv_s affect only the environment that is local to the current process; you cannot use them to modify the command-level environment.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx
To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.
Okay, wenn ich das richtig verstanden habe sind die putenv geschriebenen Variablen nur für die jeweilige Session verfügbar...
Aber wie funktioniert das mit dem Broadcasten? und dem lParam, hab es mir durchgelesen, aber ganz so viel versteh ich von C++ doch noch nicht?
Kann mir da jemand eine kleine Hilfestellung geben?
Würde die Variable gerne fest eintragen!
-
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944(v=vs.85).aspx
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, ..., (LPARAM) "Environment");
Ich hab jetzt nicht nachgesehen, ob wParam noch einen bestimmten Wert benötigt, oder ob einfach 0 übergeben werden kann.