Archive: AddToPath bug?


AddToPath bug?
I am trying to use AddToPath.

1. If PATH is not set for the user AddToPath returns an error. Is this a known bug? Am I doing something wrong?

2. Is there a way to use the current function to set path in HKLM?

3. It looks like if the PATH is in the current environment it will not be added. It may have been a leftover from some other process (previous aborted installation?), but not added to the registry. This is probably wrong.

Thx
dB.


  1. How does it return an error?
  2. AddToPath already sets the variable in the registry, if running on NT.
  3. I don't understand. What do you mean by the current environement? How can a variable be left over from another process?

I'll try to be more clear ;)

1. It fails and sets an error. I didn't dig into why.

2. There're two sets of PATHs in Windows, your personal path and the system path. It sets the personal path. I want to set the system path.

3. Let me describe a better real world scenario.
- I have an installer that does AddToPath c:\foobar.
- I already have c:\foobar in HKCU, but the installer sets path in HKLM.
- My current environment is a combination of HKLM and HKCU, hence the installer will never set the HKLM path, which is wrong.

Thx
dB.


  1. The function wasn't designed so you can use IfErrors to check for errors after it ran. How exactly does it fail? Does it just set the error flag? Does it write the new value to the registry but doesn't notify about the change? Does it skip writing the new value at all?
  2. Define ALL_USERS before including the header file.
  3. It's a combination of both and because of that, you already have that path in the PATH variable. That's why it doesn't add it.

Thanks for the replies.

1. How exactly am I supposed to check for errors? The functions sets the error flag. It does not write the value to the registry.

2. I have to also add a path to HKCU. I can't have both I presume. I guess I'll have to fork that function...

3. Well this seems plain wrong from what the installer is trying to accomplish. I need to set the path for all users, not just for the current user installing the application.

Thx
dB.


  1. You're not supposed to. I didn't think of this issue when I wrote it. As for the problem again, I realized I don't really understand it. What do you mean by the PATH not being set? I originally thought you meant the PATH key doesn't exist in the registry key, but that shouldn't be a problem.
  2. Indeed, you can't have both. You can create two copies of the header with different function names. I think there's also a function in the Wiki that accepts this setting on the stack and not as a define. It might be for general environment variables though and not PATH specifically.
  3. Then remove the check :)