1

I've written an installer for windows using NSIS. If the program is run from a console i want to write some information to this console.

My code looks like the one in this question...

NSIS - printing to prompt during command line install

System::Call 'kernel32::GetStdHandle(i -11)i.r0' 
System::Call 'kernel32::AttachConsole(i -1)i.r1' 
FileWrite $0 "hello" 

There is no problem with the installer. But if i run the uninstaller there is no output and $1 == 0.

Is there a difference between installer and uninstaller for this case?

Community
  • 1
  • 1
ginkgo44
  • 13
  • 3

1 Answers1

1

The uninstaller will run a copy of itself from %Temp% unless you start it with the special _?=$Instdir parameter. (It does this so Delete "$Instdir\uninstall.exe" works)

This means that AttachConsole(ATTACH_PARENT_PROCESS) in the second uninstaller instance will try to attach to a parent process that does not have a console. The parent has no console because a NSIS uninstaller is a GUI application and those don't get a console automatically and the _?= handling happens before .onInit so the hack to attach to one never happens.

I don't think there is a way to work around this without using _?=. Using AttachConsole is a hack and will never work perfectly in a GUI application...

Anders
  • 97,548
  • 12
  • 110
  • 164