Systemvariable setzen [C++]

baeman

Mitglied
Hallo Leute,

moechte einige Systemvariablen fuer einen neuen Prozess erstellen, und diese nach dem Prozess wieder loeschen, kann mir jemand helfen?

thanks,
Manu
 
moin


Erstellen:
Code:
SetEnvironmentVariable

The SetEnvironmentVariable function sets the contents of the specified environment variable for the current process.


BOOL SetEnvironmentVariable(
  LPCTSTR lpName,
  LPCTSTR lpValue
);

Parameters
lpName 
[in] Pointer to a null-terminated string that specifies the name of the environment variable. The operating system creates the environment variable if it does not exist and lpValue is not NULL. 
lpValue 
[in] Pointer to a null-terminated string that specifies the contents of the environment variable. An environment variable has a maximum size limit of 32,767 bytes, including the trailing null terminator. 
If this parameter is NULL, the variable is deleted from the current process's environment.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Auslesen:
Code:
GetEnvironmentVariable

The GetEnvironmentVariable function retrieves the contents of the specified variable from the environment block of the calling process. The contents are in the form of a null-terminated string of characters.


DWORD GetEnvironmentVariable(
  LPCTSTR lpName,
  LPTSTR lpBuffer,
  DWORD nSize
);

Parameters
lpName 
[in] Pointer to a null-terminated string that specifies the name of the environment variable. 
lpBuffer 
[out] Pointer to a buffer that receives the contents of the specified environment variable. An environment variable has a maximum size limit of 32,767 characters, including the null-terminating character. 
nSize 
[in] Size of the buffer pointed to by the lpBuffer parameter, in TCHARs. 
Return Values
If the function succeeds, the return value is the number of TCHARs stored into the buffer pointed to by lpBuffer, not including the terminating null character.

If lpBuffer is not large enough to hold the data, the return value is the buffer size, in TCHARs, required to hold the value string and its terminating null character.

If the function fails, the return value is zero. If the specified environment variable was not found in the environment block, GetLastError returns ERROR_ENVVAR_NOT_FOUND.

Sollte das nicht reichen, stell deine Frage mal genauer.


mfg
umbrasaxum
 
Hey, erstmal danke


Hab es auch schon mit den beiden Funktionen versucht, aber komme nicht weiter.

Versuche es genauer zu schildern, also folgende Ausgangssituation:

Mein C++ Prog(MS Visual Studio.NET) soll eine externe Exe-Datei (Fortran90) aufrufen, die auf die SystemVariablen zugreift. Welche die Dateipfade der benotigten Dateien enthalten.
Bevor ich also die ExeDatei aufrufen kann, muessen Systemvariablen mit den entsprechenden Pfaden gesetzt werden. Und erst dann der Aufruf erfolgen. Ansonsten findet das FortranProg die Dateien nicht. (Das FortranProg hab ich nicht geschrieben, und kann also auch nicht geaendert werden)

Wie kann ich einen neuen EnvironmentBlock erzeugen, den ich dann beim Aufrufen uebergebe? Komme mit dem MSDN Beispiel nicht weiter.

Hab es mit CreateProcess versucht, am einfachsten waere es wenn es mit WinExec gehen wuerde, zum Beispiel so

Code:
SetEnvironmentVariable("PLOTOUT", "c:\test\Work\decay.out");
SetEnvironmentVariable("PLOTPLT1", "c:\test\Work\decay1.plt");
SetEnvironmentVariable("PLOTPLT2", "c:\test\Work\decay2.plt");

WinExec("C:\\test\\fd\\lib\\win\\Calc_Fort.exe",SW_SHOWNORMAL);

was aber nicht geht

Hoffe es ist jetzt etwas verstaendlicher!
 
Zurück