From 560bf57fd1c93c6f9e0b849c74bb07bc3fe4a08f Mon Sep 17 00:00:00 2001 From: Arul <33111213+sarul84@users.noreply.github.com> Date: Thu, 21 Mar 2019 12:37:25 +0530 Subject: [PATCH 1/3] Option to run updater on another user account Added option to run the updater on another user account (flag to indicate if want to run as another user and NetworkCredential object for obtaining another user credentials) --- AutoUpdater.NET/AutoUpdater.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs index b7d9e44f..5d7b26d8 100644 --- a/AutoUpdater.NET/AutoUpdater.cs +++ b/AutoUpdater.NET/AutoUpdater.cs @@ -119,6 +119,16 @@ public static class AutoUpdater /// If this is true users can see the skip button. /// public static Boolean ShowSkipButton = true; + + /// + /// Set this to true if you want to run updater on another account other than current user or admin. Very usefull in the case of service account + /// + public static bool RunUpdateAsUser = false; + + /// + /// Set credentials for service account which will be used to invoke updater + /// + public static NetworkCredential ServiceAccount; /// /// If this is true users can see the Remind Later button. @@ -821,4 +831,4 @@ public override string ToString() return $"Basic {token}"; } } -} \ No newline at end of file +} From 2d05dfe74f51f32dc64d434d030194a274b5a663 Mon Sep 17 00:00:00 2001 From: Arul <33111213+sarul84@users.noreply.github.com> Date: Thu, 21 Mar 2019 12:42:13 +0530 Subject: [PATCH 2/3] Logic to set run as user credentials Added logic for setting user credential to process if "RunUpdateAsUser" flag is true --- AutoUpdater.NET/DownloadUpdateDialog.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/AutoUpdater.NET/DownloadUpdateDialog.cs b/AutoUpdater.NET/DownloadUpdateDialog.cs index cb5f3976..9bb1bc84 100644 --- a/AutoUpdater.NET/DownloadUpdateDialog.cs +++ b/AutoUpdater.NET/DownloadUpdateDialog.cs @@ -222,6 +222,18 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent { processStartInfo.Verb = "runas"; } + + if(AutoUpdater.RunUpdateAsUser && AutoUpdater.ServiceAccount != null) + { + SecureString ssPwd = new SecureString(); + + Array.ForEach(AutoUpdater.ServiceAccount.Password.ToCharArray(), + (x) => ssPwd.AppendChar(x)); + + processStartInfo.Domain = AutoUpdater.ServiceAccount.Domain; + processStartInfo.UserName = AutoUpdater.ServiceAccount.UserName; + processStartInfo.Password = ssPwd; + } try { @@ -334,4 +346,4 @@ protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult r return webResponse; } } -} \ No newline at end of file +} From 9326a64ea7570cb2e9f1a7078bc9755efa6ddffe Mon Sep 17 00:00:00 2001 From: Arul <33111213+sarul84@users.noreply.github.com> Date: Thu, 21 Mar 2019 19:26:07 +0530 Subject: [PATCH 3/3] fixed issue with secure pwd --- AutoUpdater.NET/DownloadUpdateDialog.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AutoUpdater.NET/DownloadUpdateDialog.cs b/AutoUpdater.NET/DownloadUpdateDialog.cs index 9bb1bc84..1b16324c 100644 --- a/AutoUpdater.NET/DownloadUpdateDialog.cs +++ b/AutoUpdater.NET/DownloadUpdateDialog.cs @@ -227,8 +227,8 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent { SecureString ssPwd = new SecureString(); - Array.ForEach(AutoUpdater.ServiceAccount.Password.ToCharArray(), - (x) => ssPwd.AppendChar(x)); + Array.ForEach(AutoUpdater.ServiceAccount.Password.ToCharArray(), ssPwd.AppendChar); + ssPwd.MakeReadOnly(); processStartInfo.Domain = AutoUpdater.ServiceAccount.Domain; processStartInfo.UserName = AutoUpdater.ServiceAccount.UserName;