How do I restart explorer.exe with an NSIS installer? - nsis

Running the following (hacky) code will gracefully shut down explorer.exe, but re-opens it as a window (not the taskbar).
FindWindow $R0 "Shell_TrayWnd"
SendMessage $R0 0x5B4 0 0
Exec "explorer"
However, if I type "explorer" from a cmd window, it opens the taskbar just fine.
Someone is bound to ask "Why do you want to kill explorer.exe?" -- to these people, I say, "shell extensions :|"

You can try adding a Sleep before the Exec call. (Explorer calls undocumented shell functions to register itself as Progman+Taskbar, if the old explorer process still exists this call will fail)
There are of course other problems. There can be other applications that also have your extension loaded or even another Explorer if you are registered under HKCR/HKLM.

I want to refresh desktop icon after installed app, so I try to restart explorer with exec bat file in nsis, But it doesn't work(sometime it just pop explorer windows, and toolbar disappear). Finally I find the plug-in(https://nsis.sourceforge.io/NsRestartExplorer_plug-in), that solve my problem.

Related

Electron shell.openExternal can't open some .lnk shortcuts

I'm creating a launcher using electron. It launches applications and files in my Windows system using the shell.openExternal command.
It works well when I call shell.openExternal passing .lnk shortcuts as parameters, but when I call some apparently equal shortcuts created by, for example, GoG installers, the game is not launched and I can't debug what happens. I know that the shortcut is called but the target application crashes. I got this message from Lichdom: Battlemage launcher:
Witcher 3 also fails, nos message is displayed. When I call these shortcuts directly from the system, they work fine. If I manually create an apparently exact same shortcut to the same file, it launches normally in both electron and the explorer.
Any ideas what could be happening or how to debug?

Desktop App Creator freezes and won't work

I'm trying convert .exe into .appx.
I'm using Desktop App Creator, a tool offered by Microsoft.
I've followed their documentation with no problem so far, and when I execute the command to perform the conversion (in verbose mode) the program freezes at the same point every time I launch it (with no errors/exceptions/warnings before the freeze).
In the block of the verbose "Running Installer in Isolated Environment", the last verbose line shown is "Waiting for installer process to complete inside Isolated Environment".
I've left it for 2h waiting but nothing happens.
Also, the only way to stop the shell is to close the window, it seems to be unresponsive for Ctrl+C.
I would appreciate any help for this, there's nothing to be found in the program's documentation about this.
Thanks a lot in advance and regards.
I had the same problem. The solution is that you need to run your installer in the isolated environment in silent mode in order to not display the wizard menu, because you cannot see the isolated environment and click the on the wizard buttons.
Add to DesktopAppConverter -Installer this argument:
-InstallerArguments /SILENT
Before running make sure you can install your application in silent mode by running:
setup.exe /SILENT
I had the same problem a few days ago
replacing "/S" argument with "/quiet" in -InstallerArguments, for me worked!

NSIS ExecWait not launching secondary installer

I have a basic NSIS installer that is supposed to call a secondary - non-NSIS installer like so:
Section "Install First" SEC01
File "WindowsPathToFile\setup.exe"
DetailPrint "Installing the first Thing"
ExecWait '"$INSTDIR\setup.exe"'
SectionEnd
NSIS and the installer do not throw any errors - however the sub installer is never launched or executed (and the application is never installed).
Note that if I put the call to "setup.exe" in a batch script and launch the batch script this does work. I was just hoping for something more elegant (that doesn't display the command prompt) as I'll have several custom installers that need to be called.
I didn't think that the ExecWait chain issue detailed in "ExecWait Doesn't Wait" would affect me as I don't think my (setup.exe) installer is extracting a secondary installer.
The setup.exe installer is created by LabVIEW and I haven't found good information on what it's doing behind the scenes.
Am I missing something here? Or do I just need to stick with the batch script?
Does the secondary installer require elevation? Do you have RequestExecutionLevel admin in your .nsi?
ExecWait internally calls the CreateProcess Windows API function and it will fail if the child process needs to be elevated by UAC.
If you are going to execute a child process that requires elevation then it is generally recommended that your installer requires elevation as well. If you for some reason don't want to do this then you can use ShellExecWait or ${StdUtils.ExecShellWaitEx}.

How to run something just before the files are installed?

I would like to know how to run something just before files are installed using NSIS.
I know about the .onInit function. That function runs when the installer is first starting. That is not what I want. I would like to run something after the user has clicked the install button but before the files actually get installed.
To be more specific. I have a windows service. When the installer is upgrading the windows service, I need it to stop the service - but only once the user is committed to the install - not when first starting the installer. Then it can upgrade the files and finally (re)start the service again. This seems like it should be a common requirement, but I haven't been able to find anything.
If it matters I'm using the MUI instead of classic.
All sections are executed on the instfiles page and they are executed in the same order as your source .nsi so you can just add another (hidden) section:
Section
# Do service stuff...
SectionEnd
Section "Required Files"
File xyz.abc
SectionEnd
Section
# Do service stuff...
SectionEnd
As Anders said - create invisible (hidden) section which is very first of all sections in your script and stop the service there.
When the other sections will be executed the service will be stopped.
Tip: maybe you should wait few seconds to let service manager time to stop the service.

How to run Application.exe before windows startup?

I have a windows application with user Interface that do some stuff...
Now my client wants that, when he pushes the power button MyApplication run before he forced to input the username and password!
comment: the system is multi user on windows XP or Seven.
Is it possible anyway?
I found the way to do this was to create a scheduled task with a trigger for "on startup". This starts the application before windows logon. This is particularly useful in a server type environment if you need to have something run that is not a service.
It is simple. The process is.
Run gpedit.msc
Go to computer Configuration -> Windows Setting -> Scripts(Startup/shutdown)
Go to Startup properties then you will get the new windows.
Now add the program that you want to run before login.
The right way to do this is to implement a Windows service.
I've used this article here as I run a Minecraft server which I need to have the console interactive so I can manage the server and running it as a service is not a good solution in such a case: https://www.tenforums.com/tutorials/138685-turn-off-automatically-restart-apps-after-sign-windows-10-a.html
What I did was edit the registry:
Go to HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Create a new DWORD value (if this DWORD doesn't exist already) and
call it RestartApps with the value of 1
This now starts apps that usually startup before you log in and starts the programs in shell:startup
You can not run an exe without first loading the operating system. You can, however, run the exe without logging in first. Just add copy and paste the shortcut for the exe into C:\Documents and Settings\Administrator[or other user name]\Start Menu\Programs\Startup. Then check msconfig to make sure your exe is checked to run on startup.

Resources