Running msiexec from a service (Local System account)

余生颓废 提交于 2019-12-05 01:06:57
Andrey Tagaew

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.

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.

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.

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.

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