Darksody
Darksody

Reputation: 539

Silent install msi from a windows service local service account

I am building an auto-updating mechanism. A windows service that runs on a local service account responsible with the auto-updating of a msi.

The service downloads the msi file then it tries to install it using this code:

Process process = new Process();
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = string.Format(" /i \"{0}\" /qn /norestart ALLUSERS=1", sMSIPath);
process.Start();
process.WaitForExit();

Where sMSIPath is a string representing the path to the file, for example "C:\test.msi".

This code, from a regular console application seems to be running fine. I managed to silently install adobe reader, for example.

But from my windows service, it does nothing. According to the logs, i get a warning with this message: Failed to connect to server. Error: 0x80070005 Where the user is "LOCAL SERVICE" (as i mentioned, my windows service runs as a local service).

Also, the projects have target x86, but i am running a 64-bit OS. (i need them at x86, i want this software to be able to run on multiple operating systems).

Any help is very well received. Thanks alot!

Upvotes: 2

Views: 3735

Answers (2)

PhilDW
PhilDW

Reputation: 20790

I don't think you have much chance of making this work. If the MSI tries to access folders like Desktop, User's Program Menu, the CommonFilesFolder (not a complete list) or looks at the LogonUser property and any number of other things it will fail because in a normal install from the interactive user these are all valid properties associated with that installing user. When the installing user is localservice you're likely to be in a mess.

If you need to do this, configure the service to run as a valid administrator account - that might give you a chance of it working better. It's possible that the failure to connect to server error is because MSI files are expected to be run from some kind of user account.

Upvotes: 2

Pankaj Kapare
Pankaj Kapare

Reputation: 7812

  1. Open service management console Start->Run->Services.msc
  2. Right click on your service and go to properties
  3. On property page select second tab i.e. "Log On"
  4. Check checkbox called "Allow Service to interact with desktop".

Upvotes: 1

Related Questions