Running msiexec from a service (Local System account)

拥有回忆 提交于 2019-12-06 18:18:19

问题


We are working on an update system for our software. The updater should run in the background as a service, and when an update is available, download and install it. We need the service to install the update since the MSI requires elevation to run, but some of our clients will be restricted users.

The MSI is a WiX MSI and does a major upgrade when run. The problem is, the update does not seem to work when run from our service. I can see msiexec run, and it returns successfully, but it seems to make no changes to the system. The same command, when run from my user account works as expected.

Is there some caveat to running msiexec from a Local System service?

We are simply doing:

string arguments = "/i /quiet /lv*x " + pathToLogFile;   
System.Diagnostics.Process.Start("msiexec.exe", arguments);

回答1:


If your service is a Windows service then do the following steps:

  1. Open properties of your service in Services console.

  2. Go to the Log On tab

  3. Set an account that has rights to update the system (yours or specially created for this purpose)

  4. Restart the service

In this case, the service will be run with proper rights and can do updates.




回答2:


In case anyone else runs into this, here's what I was finding.

I was installing a program from a service being run as LocalSystem. The installation would return immediately with exit code 0. However, the program didn't seem to be installed. The files were not copied into place, and no shortcuts were created. Looking in the log file was difficult because it didn't have a simple success or failure message. When I ran the service as a normal administrator account, it worked fine. I did finally notice in the log file that it said

Determined that existing product (either this product or the product being upgraded with a patch) is installed per-machine.

It was not listed as installed in Control Panel > Programs, but for some reason Windows thought it was already installed. Unfortunately, running msiexec /x to uninstall the program had no effect either.

I tried changing the product code and upgrade code, and viola, it worked. In my case, I controlled the installation product code and upgrade codes, so I could do that. If in someone else's case, you don't have such access, you might try installing some other arbitrary piece of software (which will have a different product/upgrade code) and see if that works, and if it does, at least you know that's the issue.




回答3:


I also had the same task described above and I found that if program was installed for ALL users, running msiexec would work from Service which is running under SYSTEM account. So to make this work, you will have to install for ALL users. In my case, I specified msxexec command as follows when the program is first installed.

msiexec /i setup.msi ALLUSERS="1"

Once this is done, you can just upgrade the program from Service without any issue.




回答4:


You may need to use the REINSTALLMODE parameter that allows you to control the upgrade. If they are not provided, the installation may silently fail to upgrade your app (or at least that's what I've found, though I'm still a little unsure whether the same behaviour applies under System.Diagnostics.Process.Start):

msiexec.exe /i /quiet yourinstaller.msi REINSTALL=All REINSTALLMODE=vomus

See here for more info on the various flags that you can pass to msiexec.exe.



来源:https://stackoverflow.com/questions/2603969/running-msiexec-from-a-service-local-system-account

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