Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

windows - What are these strange environment variables?

I use GetEnvironmentString() to get the program's environment variables.

Every program has such result in the first:

=::=::

I don't know what does it mean?

Here is the code :

LPWCH lpEnvString=GetEnvironmentStringsW();
 LPWSTR lpszVariable=(LPWSTR)lpEnvString;
 while (*lpszVariable)
 {
     wprintf(L"%s
",lpszVariable);
     lpszVariable+=wcslen(lpszVariable)+1;
 }
 FreeEnvironmentStringsW(lpEnvString);

Also if we start listing such variables we would see stuff like:

=::=::
=C:=C:Usersusernamevalue
=ExitCode=00000001
ALLUSERSPROFILE=C:ProgramData
APPDATA=C:UsersartikAppDataRoaming
CommonProgramFiles=C:Program Files (x86)Common Files
CommonProgramFiles(x86)=C:Program Files (x86)Common Files
CommonProgramW6432=C:Program FilesCommon Files
...

On the other hand, getenv("=ExitCode") or getenv("=C:") returns NULL.

Can you provide a proper documentation of this "feature", for example getenv() ignores such strings and how such values should be treated?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

They are leftovers from cmd.exe emulating ms-dos directory handling, they basically have little use, and are more archaic than anything. Essentially, it keeps track of a per drive current directory, and is kept as an environment variable to pass to other processes with ease.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...