AutomaticUpdaterBackend & wyUpdate does not work if started from scheduled task

Hello!

I created scheduled windows task. This task uses local system account and starts when user is logged on. The task runs my program that uses AutomaticUpdaterBackend.

All operations in the code work right, but wyUpdate does not update files.

P.S. I trIed start wyUpdate using Process.Start, it also does not work.

Code:

private static void ApplyPatch(string patchFolder)		{			var appFolder = _startupDirectory;			var logFile = Path.Combine(appFolder, "wyUpdate.log");


			Process[] wyUpdateProcesses = Process.GetProcessesByName("wyUpdate");


			foreach (var proc in wyUpdateProcesses)			{				WriteMessage("wyUpdate process was found and killed.");				proc.Kill();			}


			_auBackend = new AutomaticUpdaterBackend			{				GUID = "CeALauncher_AutoUpdate",				UpdateType = UpdateType.Automatic,				wyUpdateCommandline = string.Format("-updatepath=\"{0}\"", patchFolder),			};


			_auBackend.CheckingFailed += auBackend_CheckingFailed;			_auBackend.UpdateAvailable += auBackend_UpdateAvailable;			_auBackend.DownloadingFailed += auBackend_DownloadingFailed;			_auBackend.ExtractingFailed += auBackend_ExtractingFailed;			_auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled;			_auBackend.UpdateSuccessful += auBackend_UpdateSuccessful;			_auBackend.UpdateFailed += auBackend_Failed;			_auBackend.UpToDate += auBackend_UpToDate;




			// Initialize() and AppLoaded() must be called after events have been set.			// Note: If there's a pending update to be installed, wyUpdate will be			//       started, then it will talk back and say "ready to install,			//       you can close now" at which point your app will be closed.			_auBackend.Initialize();			_auBackend.AppLoaded();




			if (!_auBackend.ClosingForInstall && _auBackend.UpdateStepOn == UpdateStepOn.Nothing)			{				_auBackend.ForceCheckForUpdate();			}


			//			_resetEvent.WaitOne();


		}


		private static void auBackend_UpToDate(object sender, SuccessArgs e)		{			WriteMessage("Files is up to date.");			_resetEvent.Set();		}


		private static void auBackend_CheckingFailed(object sender, FailArgs e)		{			WriteMessage(string.Format("Checking failed: {0}.", e.ErrorMessage));			_resetEvent.Set();		}


		private static void auBackend_UpdateAvailable(object sender, EventArgs e)		{			WriteMessage("Update available.");			_resetEvent.Set();		}


		private static void auBackend_DownloadingFailed(object sender, FailArgs e)		{			WriteMessage(string.Format("Downloading failed: {0}.", e.ErrorMessage));			_resetEvent.Set();		}


		private static void auBackend_ExtractingFailed(object sender, FailArgs e)		{			WriteMessage(string.Format("Extracting failed: {0}.", e.ErrorMessage));			_resetEvent.Set();		}


		private static void auBackend_ReadyToBeInstalled(object sender, EventArgs e)		{			// ReadyToBeInstalled event is called when			// either the UpdateStepOn == UpdateDownloaded or UpdateReadyToInstall


			if (_auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall)			{				WriteMessage("Ready to install.");				_auBackend.InstallNow();			}


			_resetEvent.Set();		}


		private static void auBackend_UpdateSuccessful(object sender, SuccessArgs e)		{			WriteMessage("Update successful.");			_resetEvent.Set();		}


		private static void auBackend_Failed(object sender, FailArgs e)		{			WriteMessage(string.Format("Update failed: {0}.", e.ErrorMessage));			_resetEvent.Set();		}

Process[] wyUpdateProcesses = Process.GetProcessesByName("wyUpdate");

foreach (var proc in wyUpdateProcesses){WriteMessage("wyUpdate process was found and killed.");proc.Kill();}

Why are you doing this? It's completely unnecessary and does more harm than good.

P.S. I trIed start wyUpdate using Process.Start, it also does not work.

What do you mean "it doesn't work"? Exactly what happened? Did you check for updates? What was the output, errors, etc.? Did it succeed? Did you try starting the update? What happens?

Process[] wyUpdateProcesses = Process.GetProcessesByName("wyUpdate");

foreach (var proc in wyUpdateProcesses){WriteMessage("wyUpdate process was found and killed.");proc.Kill();}

Why are you doing this? It's completely unnecessary and does more harm than good.

Do not pay attention for this. I thought that the reason for the second instance.

What do you mean "it doesn't work"? Exactly what happened? Did you check for updates? What was the output, errors, etc.? Did it succeed? Did you try starting the update? What happens?

Previous version of the method ApplyPatch was

private static void ApplyPatch(string patchFolder) { patchFolder = patchFolder.TrimEnd('\\'); var appFolder = _startupDirectory; var logFile = Path.Combine(appFolder, "wyUpdate.log"); WriteMessage(string.Format("Log file {0}", logFile));

Process.Start(string.Format(@"{0}\wyUpdate.exe", appFolder), string.Format("/fromservice -updatepath=\"{0}\" -logfile=\"{1}\"", patchFolder, logFile)); }

Result: Logfile is empty. Files was not updated.

I tried this version:

private static void ApplyPatch(string patchFolder) { patchFolder = patchFolder.TrimEnd('\\'); var appFolder = _startupDirectory; var logFile = Path.Combine(appFolder, "wyUpdate.log");

WriteMessage(string.Format("Log file {0}", logFile));

Process.Start(string.Format(@"{0}\wyUpdate.exe", appFolder), string.Format("-updatepath=\"{0}\" -logfile=\"{1}\"", patchFolder, logFile)); }

Result: Logfile is empty. Files was not updated.

If I start my console application from cmd.exe it works perfectly. If it runs from scheduled task, wyUpdate does not update files.

Result: Logfile is empty. Files was not updated.

You can't use /fromservice because you're not running it from a service. http://wyday.com/wybuild/help/wyupdate-commandline.php#fromservice

Thus at best you'll get an error and no log file.

Also, you're not checking the return codes. And, you're running things from scheduled tasks and you're assuming they'll have admin permission (they won't -- hence the failures). If you want to run wyUpdate in the background then do it from a LocalSystem service.