I have a windows service that runs every 10 minutes and checks to make sure that all of the correct parts of our software are installed and up-to-date. Every time that the service executes, it uses the following function to install an executable:
public static bool InstallControlPanel()
{
try
{
//this will change
string sSetupFile = @"C:\Projects\SyncAgentV2\SyncAgentV2.ControlPanel.Installer\SyncAgentV2.ControlPanel.Installer\Express\SingleImage\DiskImages\DISK1\setup.exe";
if (!System.IO.File.Exists(sSetupFile))
{
Debug.WriteLine("Service Installer doesn't exist.");
return false;
}
Process oProcess = new Process();
oProcess.StartInfo.ErrorDialog = true;
oProcess.StartInfo.UseShellExecute = true;
oProcess.StartInfo.Arguments = "/s /v/qn";
oProcess.StartInfo.FileName = sSetupFile;
oProcess.Start();
oProcess.WaitForExit();
return true;
}
catch (Exception oEx)
{
Debug.WriteLine(oEx);
return false;
}
}
When I debug this method when it is called from the service, it runs and progresses through all of the steps, returning true, but it does not install the executable. I can call this method from a WPF and it works, so the problem must be the way that the service calls it.
Right now, the service is set to log on as Local System. I suspect that a service cannot operate the way that I want it to or that I need it to log on as a different user. Can someone verify this or point me in a different direction?
EDIT: This method works, but not when I call it from a service.