VS1928
VS1928

Reputation: 67

NSIS with admin access fails to create reg key via batch script

I have a NSIS script with RequestExecutionLevel admin set and within this I invoke a .bat script which adds a reg key.

When the is executed through the reg key gets added. But when running the installer, it executes the .bat file but fails to add the reg key.

nsExec::ExecToStack '"$pluginsdir${SETUP_PATH}\UpdateNtpConfiguration.bat" $Ip1'

UpdateNtpConfiguration.bat content

set adds=%1
REM Get the list of ntp servers showing up in System Date & Time->Internet Time dropdown
set "num=0"
for /F %%G in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers ^| findstr "^[^a-z] ^("') do if %%G GTR !num! set "num=%%G"
set /A num=num + 1
REM Add address at the end
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers /v "%num%" /t REG_SZ /d  "%adds%" /f
goto:eof

Upvotes: 2

Views: 185

Answers (2)

VS1928
VS1928

Reputation: 67

After some debugging found out that NSIS was writing the registry values in 32 bit reg space(HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft). I had to append /reg:64 to make it add to the 64 bit reg space.

Also the reason I had the bat script was to have some logic to look for duplicates before adding the key.

Upvotes: 1

mr noob
mr noob

Reputation: 365

Just like @Anders said, there are built in functions for that. https://nsis.sourceforge.io/Docs/Chapter4.html#registry

If an an error happens with this command, it will be a lot easier to debug as it is built-in.

If you're not doing anything else in the batch file, it is better to find out if NSIS has a command already integrated with it....

EDIT:

It also might be that the admin installer is run the bat file without admin privs.

Upvotes: 1

Related Questions