Re: GenEnvironmentVariable and CreateProcess failures under XP
From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 04/23/04
- Next message: Peter Huang: "RE: GenEnvironmentVariable and CreateProcess failures under XP"
- Previous message: dbrn: "Re: ShowWindow is not working"
- In reply to: LarryH: "GenEnvironmentVariable and CreateProcess failures under XP"
- Next in thread: LarryH: "Re: GenEnvironmentVariable and CreateProcess failures under XP"
- Reply: LarryH: "Re: GenEnvironmentVariable and CreateProcess failures under XP"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 23 Apr 2004 01:56:08 -0400
I'm not sure where you got your info on the meaning of the return values for
GetEnvironmentVariable ...
-----------
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.
--------------
If you first call GetEnvironmentVariable with a 0-length string, the return
value will indicate the size you need to pad the string to retrieve the
data. A return value of '1' does not necessarily therefore = success.
My first suggestion to approach the debugging of these calls on NT-based
systems is to ensure that all strings used in the APIs are null-terminated.
NT is very picky about the formatting of strings, something 9x machines
allow a lot of grace on.
My second suggestion - since it's not clear in your message - would be to
ensure SetEnvironmentVariable is not being called prior to your executing
the external apps, especially if it is adding paths to the PATH environment
setting. There is a limit to the size this string can be, and repeated
calling may be adding your custom path multiple times, thereby exceeding
this limit.
Finally, it is important to realize that environment changes made by the
call(s) to SetEnvironmentVariable only affect the environment for your
application. It does not affect the "system environment" that other
applications see. As the MSDN remarks state ... "This function has no effect
on the system environment variables or the environment variables of other
processes." Perhaps you are relying on those applications to use your
newly-amended environment?
-- Randy Birch MVP Visual Basic http://vbnet.mvps.org/ Please respond only to the newsgroups so all can benefit. "LarryH" <BigLar@nospam.nospam> wrote in message news:B1533CE0-AC69-4AC8-A3DF-398662B8A9E0@microsoft.com... : I am having truble figuring out how to debug a problem with VB6 program that shells other Win32 executables. The program has been running for years and was just recompiled under Windows XP Pro SP1. The problem is with calls to the Win32 API not returning results even though the exit code indicates success. The program calls GenEnvironmentVariable to get the sytem PATH, SetEnvironmentVariable to prepend a value to the system PATH, then calls CreateProcess to launch Notepad or other Win32 executables. I can launch Notepad 6 or 7 times in a row with no problem, then I start getting one of three unexpected results. The unexpected results are: : : (1) GetEnvironmentVariable fails to return anything, but still returns "1" to indicate success, : (2) CreateProcess fails to launch Notepad (or whataver is called), but still returns "1" to indicate success, : (3) Createprocess fails to launch Notepad (or whataver is called) and returns "0" to indicate failure. : : Once an unexpected result happens, it will happen on all subsequent attempts to launch that program until I shut the program down (when debugging, I have to shut VB 6 down). Only the third result makes sense. The Event log is not updated by any of these errors. : : I cannot find any information on this problem in the MSDN library or through Internet searches, including some of the more popular VB sites. : : I have also been told that this problem ocurrs infrequently on Windows NT, but only happens once, not continuously. On XP, of the two PCs we are testing on, one computer produces the unexpected results a lot more frequently that the other. All of our PCs are locked down and all software is remotely installed. Our workstation people looked at the computers and say the same patches have been applied to each. I can replicate this problem at will. : : Is this a known problem? What can I do about it? If it is unfamiliar, what tools do I need to debug it?
- Next message: Peter Huang: "RE: GenEnvironmentVariable and CreateProcess failures under XP"
- Previous message: dbrn: "Re: ShowWindow is not working"
- In reply to: LarryH: "GenEnvironmentVariable and CreateProcess failures under XP"
- Next in thread: LarryH: "Re: GenEnvironmentVariable and CreateProcess failures under XP"
- Reply: LarryH: "Re: GenEnvironmentVariable and CreateProcess failures under XP"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|