1

I am looking for a way to use prompt ScheduleReboot action in WIX installer only in the condition there is more than one user logged in to the target machine. So far I couldn't find a condition or other built in way to do that, I decided to ask here before writing a custom action.

Thanks.

answers to @Stein Asmul qustions:
The app is a dev tool that could be deployed on any type of machine with any type of windows os newer than Windows xp. I need to restart on the case of more than one opened session since the app involves several user-owned processes that are being started during the installation and then on windows startup. When these processes are off for one user and on for another it could lead to an invalid state of the app, or at least to a state that we are not planning to support. Since I have no easy way to start these processes for a logged on user that is not the one who ran the installation, asking a restart is an acceptable solution for me.

I have no problem writing the code for a winform that checks the number of logged on users with a WMI query and based on the response offers to restart, even though it's always nice to use someone else's already written and tested code. I guess I could write a Wix CustomAction that saves a property indicating if the there is more than one interactive log-on and then use it as a condition for a ScheduleReboot, but like many things in Wix, it would be complicated, very hard to debug and the end result would be almost similar. I would, of course, prefer to get from somewhere a tested "Wix" way to do that since a simple winform limit my options to what I can do with Wix, but I haven't found anything and it's not something I'm going to get into right now.

Yuval Perelman
  • 4,499
  • 1
  • 22
  • 32
  • From what you write I would conclude that you should detect multiple logins and then show a message informing the user that you refuse to install until there is only one interactive logon session. Much easier than to fiddle with reboot in code. Note that if other users can't run your application unless they ran the original install - then that is a design problem. This will definitely cause trouble if your application is deployed silently via SCCM or similar - when there are no users logged on at all. Do you have a strategy for this silent deployment scenario? Are these services in user mode? – Stein Åsmul Apr 10 '18 at 00:31
  • The solution you have given is not good for me since my business goal is for the user to install it no matter what - if he needs to start dealing with other people in the team or to try to find a time when nobody is logged in he might pass on the app altogether. When you try something new you don't want headaches. About silent install - currently we have no support for that scenario, and for that specific app it's not relevant. For now I did a winform that offers to restart and it seems to be working. Far from ideal, so will leave the question open in case a better solution will pop up. – Yuval Perelman Apr 10 '18 at 12:05

1 Answers1

0

Interesting problem. Since nobody else has answered: I am not aware of any built-in features for this. I had a quick look in WiX, and I can't recall having seen support for this in commercial tools either. This is quite strange, since deployment to terminal servers would seem to require something like this?

Can we ask what environment you are deploying to? A little more details on your requirements and rationale for needing this?


It isn't quite clear from your question if you already know how to do this in code, and just want to check if there is an easier way, or if you want a code solution?

I always prefer native code for deployment. Your setup should handle any machine, in any state, in any language in any OS edition and just about any OS version. Minimal dependencies.

Below are some links. I will have to have another look tomorrow. This is a bit messy:

  1. Native Win32: I thought NetWkstaUserEnum would work, but it looks like the LsaEnumerateLogonSessions function is better as described on CodeProject - Enumerating Logon Sessions (there is ancient source code to download).

  2. Terminal Server: There also seems to be a query tool (serverfault) on Terminal Servers (that I have never tried).

  3. SysInternals: System internals offers the free tool PsLoggedOn, but it doesn't seem ideal with regards to output format. Possible though.

  4. PowerShell / WMI: There are some PowerShell scripts out there. I really dislike PowerShell for deployment, but lots of people seem to use them. I guess it is the future. Results seem inconsistent on different OS versions when using WMI it seems.

  5. .NET Framework: Cassia, an open source wrapper. PInvoke Win32.

There is always github.com to search.


Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164