How to ScheduleReboot in wix only if several sessions are opened

女生的网名这么多〃 提交于 2019-11-28 11:06:14

问题


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.


回答1:


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.


  • Powershell script to see currently logged in users (domain and machine) + status (active, idle, away)
  • https://serverfault.com/questions/32633/how-to-check-who-is-currently-logged-on-to-windows-workstation-from-command-line
  • https://blogs.msdn.microsoft.com/alejacma/2008/03/04/how-to-get-the-logged-on-user-with-wmi-vbscript/
  • WTSEnumerateSessions function
  • How do you use LsaEnumerateLogonSessions in C#?
  • https://gallery.technet.microsoft.com/scriptcenter/0e43993a-895a-4afe-a2b2-045a5146048a
  • https://serverfault.com/questions/598554/whats-the-best-way-to-see-logged-in-users-in-windows-server-2012


来源:https://stackoverflow.com/questions/49707865/how-to-schedulereboot-in-wix-only-if-several-sessions-are-opened

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!