Skip to content
⌘ NSIS Forum Archive

$EXEDIR empty

9 posts

Mircea M#

$EXEDIR empty

Hi,

I wanted to ask what I could possibly do wrong so that $EXEDIR returns an empty string. I am working on a relatively old piece of code that I took over from a colleague that left the company but as far as I can tell, he never changes the value manually anywhere.

Thanks,
Mircea
Anders#
A broken plugin could corrupt it.

Try a MessageBox at the start of .onInit and go from there to track down the source of the problem...
LoRd_MuldeR#
Originally Posted by Mircea M View Post
as far as I can tell, he never changes the value manually anywhere.
Did you also check all the .nsh files he might be including, either directly or indirectly?

Also, what version of MakeNSIS are you using to build that script? Do you use the Unicode or ANSI version?
Mircea M#
Hi,

started the MessageBox approach but it will take some time as there's a lot of code and different installation paths. Hopefully I will find something soon.

I am using the ANSI version and I also checked all the .nsh files - all seems ok in there too.

Thanks for the tips!
Mircea
Mircea M#
Ok, found the spot. It is when I am setting a new Environment Variable. I have the following function:

WriteRegExpandStr ${IDI_HOME_ROOT_KEY} "${IDI_HOME_KEY}" "${IDI_HOME_VAR}" "${IDI_HOME_VAL}"
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
StrCpy $R0 "${IDI_HOME_VAL}"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i(${IDI_HOME_VAR}, R0).r0'
The variables (constants) that I use are:

!define IDI_HOME_ROOT_KEY "HKLM"
!define IDI_HOME_KEY "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
!define IDI_HOME_VAR "IDI_HOME"
!define IDI_HOME_VAL "$INSTDIR"
After I do this, my Env. Var. is set correctly but $EXEDIR is empty. The actual line that causes the problem is the System::Call one.
Any ideas why?

I could save the value of $EXEDIR to a temporary variable and re-assign it at the end of the function but I would like to know why this happens, if I am doing something wrong.

Thanks!
Mircea M#
Update

Seems that if I remove the System::Call statements my environment variable is still available during the installation for the installer and it's sub-processes.
I did that and now everything works.
It would still be interesting to know why that System::Call "deleted" $EXEDIR 🙂
JasonFriday13#
First, move the sendmessage command down after you modify the environment variable. Also try changing the system::call function so it's char type agnostic.

Originally Posted by Mircea M View Post
WriteRegExpandStr ${IDI_HOME_ROOT_KEY} "${IDI_HOME_KEY}" "${IDI_HOME_VAR}" "${IDI_HOME_VAL}"
StrCpy $R0 "${IDI_HOME_VAL}"
System::Call 'Kernel32::SetEnvironmentVariable(t "${IDI_HOME_VAR}", t R0)'
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
If it still empties $EXEDIR then there is something else going on.
Anders#
Originally Posted by JasonFriday13 View Post
First, move the sendmessage command down after you modify the environment variable.
The broadcast applies to the registry key, moving it is not required.