On 2022-11-30, JJ <
jj4p...@outlook.com> wrote:
> On Tue, 29 Nov 2022 23:29:14 GMT, Charlie Gibbs wrote:
>> When calling CreateProcess() with lpCurrentDirectory set to NULL, the
>> child process is supposed to inherit the parent's current directory -
>> but I've learned the hard way that occasionally it doesn't. I've
>> had several instances where the child's current directory is set to
>> something random.
<snip>
> `CreateProcess()` never change the working directory. If it's changed,
> something must have changed it before `CreateProcess()` is called.
>
> Like the Open/Save dialog that you've mentioned, which may change the
> working directory depending on user input. User code is not the only one
> which may change the working directory.
What makes it hard to diagnose is that it's very infrequent (i.e. highly
intermittent), and the directory I get changed to is completely random.
> Different thread shouldn't change the working directory - even temporarily,
> because it will create a chance for other threads to use the wrong working
> directory. At least not without thread synchronization. Be it user code, or
> API. Directly or indirectly.
The programs in question are single-threaded.
> My suggestion is to debug the launcher process and place breakpoints on
> NTDLL functions which change the working directory.
I've been thinking about doing this. The trick is to find a consistent
location in which I can log the results - an absolute path is probably
needed - and how to notify the support people should it happen at one
of our many customer sites. We do have e-mail capability - if I can
detect that something has gone awry I could probably jam the current
directory back to where we belong, then trigger our e-mail program.
And then again, since any further occurrences over the past 20 years
would have been masked by my workaround, there's no telling whether
it's ever happened since. Between prorgram maintenance and various
other upgrades, it might no longer be an issue. But I'll have to
tread softly.
--
/~\ Charlie Gibbs | If your nose runs
\ / <cgi...@kltpzyxm.invalid> | and your feet smell,
X I'm really at ac.dekanfrus | you're built
/ \ if you read it the right way. | umop-apisdn.