diff --git a/Installer/Installer_Win/Golem.aip b/Installer/Installer_Win/Golem.aip
index ceee9edda0..83c7b303dc 100644
--- a/Installer/Installer_Win/Golem.aip
+++ b/Installer/Installer_Win/Golem.aip
@@ -326,7 +326,7 @@
-
+
@@ -406,7 +406,7 @@
-
+
@@ -468,7 +468,7 @@
-
+
@@ -522,6 +522,7 @@
+
@@ -614,6 +615,7 @@
+
@@ -690,6 +692,8 @@
+
+
diff --git a/scripts/docker/prepare-docker-as-admin.ps1 b/scripts/docker/prepare-docker-as-admin.ps1
new file mode 100644
index 0000000000..59d746aceb
--- /dev/null
+++ b/scripts/docker/prepare-docker-as-admin.ps1
@@ -0,0 +1,21 @@
+$ErrorActionPreference = "Stop"
+[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
+
+$RunAsAdminScript = (AI_GetMsiProperty AI_RUN_AS_ADMIN_FILE)
+"RunAsAdminScript: " + $RunAsAdminScript
+$PrepareDockerScript = (AI_GetMsiProperty AI_PREPARE_DOCKER_FILE)
+"PrepareDockerScript: " + $PrepareDockerScript
+$CreateShareScript = (AI_GetMsiProperty AI_CREATESHARE_FILE)
+"CreateShareScript: " + $CreateShareScript
+$currentUserName = (AI_GetMsiProperty RUNNING_USER)
+"currentUserName: " + $currentUserName
+
+# FIXME: LocalAppDataFolder property points to admin's AppData folder
+# $AppDataDir = (AI_GetMsiProperty LocalAppDataFolder)
+# For now we use the default temp folder used by the installer
+$pathList = $RunAsAdminScript -split "\\Temp"
+$AppDataDir = $pathList[0]
+"AppDataDir: " + $AppDataDir
+
+&"$RunAsAdminScript" -ScriptPath "$PrepareDockerScript" `
+ -ScriptParams "-createShareScript `"$CreateShareScript`" -appDataDir `"$AppDataDir`" -currentUserName `"$currentUserName`""
diff --git a/scripts/docker/prepare-docker-for-windows.ps1 b/scripts/docker/prepare-docker-for-windows.ps1
index 21b8ed3dfa..a5a79e3e30 100644
--- a/scripts/docker/prepare-docker-for-windows.ps1
+++ b/scripts/docker/prepare-docker-for-windows.ps1
@@ -1,26 +1,12 @@
# Block for declaring the script parameters.
Param(
- $createShareFolder = "",
+ $createShareScript = "",
$appDataDir = "",
- $currentUserName = "",
- $productVersion = ""
+ $currentUserName = ""
)
-if (Get-Command "AI_GetMsiProperty" -errorAction SilentlyContinue)
-{
- $createShareFolder = (AI_GetMsiProperty TempFolder)
- $appDataDir = (AI_GetMsiProperty LocalAppDataFolder)
- $currentUserName = (AI_GetMsiProperty LogonUser)
- $productVersion = (AI_GetMsiProperty ProductVersion)
-}
-
$ErrorActionPreference = "Stop"
-if ($productVersion)
-{
- $createShareFolder += $productVersion + "\"
-}
-
# Your code goes here.
$golemUserName = "golem-docker"
"golemUserName: " + $golemUserName
@@ -39,8 +25,6 @@ if( ! $currentGolemUser )
"createShareFolder: " + $createShareFolder
"appDataDir: " + $appDataDir
-$createShareScript = $createShareFolder + "create-share.ps1"
-"createShareScript: " + $createShareScript
$golemDataDir = $appDataDir + "\golem\golem\default"
$mainnetDir = $golemDataDir + "\mainnet\ComputerRes"
diff --git a/scripts/run-as-admin.ps1 b/scripts/run-as-admin.ps1
new file mode 100644
index 0000000000..2ac9a7d438
--- /dev/null
+++ b/scripts/run-as-admin.ps1
@@ -0,0 +1,48 @@
+<#
+
+.SYNOPSIS
+This is a script for running an arbitrary powershell script with administrator privileges.
+
+.EXAMPLE
+.\run-as-admin.ps1 -ScriptPath "C:\Users\golem\my-script.ps1" -ScriptParams "-Param1 `"this is example`""
+
+#>
+
+param(
+ [Parameter(Mandatory=$true)] [string] $ScriptPath,
+ [Parameter(Mandatory=$false)] [string] $ScriptParams = ""
+)
+
+$ErrorActionPreference = "Stop"
+[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
+
+# Convert path to absolute
+$ScriptPath = Convert-Path -Path $ScriptPath
+
+# Creating temporary files for capturing stout & stderr
+$StdoutPath = (New-TemporaryFile).FullName
+$StderrPath = (New-TemporaryFile).FullName
+$TmpScriptPath = "$env:TEMP/tmp-script.ps1"
+
+# Generate code for a script that will capture the original script's stdout & stderr
+# This is done because powershell cannot redirect output of a process started with 'RunAs' verb
+@"
+`$ErrorActionPreference = "Stop"
+[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
+
+try {
+ &"$ScriptPath" $ScriptParams >"$StdoutPath" 2>"$StderrPath"
+} catch {
+ `$_ | Out-File -FilePath "$StderrPath" -Encoding "UTF8"
+ throw
+}
+"@ | Out-File -Encoding "UTF8" -FilePath $TmpScriptPath
+
+$Process = Start-Process -FilePath "powershell.exe" `
+ -ArgumentList "-NoProfile -NoLogo -ExecutionPolicy RemoteSigned `"$TmpScriptPath`"" `
+ -Wait -PassThru -Verb RunAs -WindowStyle Hidden
+
+Get-Content -Encoding "UTF8" -Path $StdoutPath | Write-Output
+Get-Content -Encoding "UTF8" -Path $StderrPath | Write-Error
+
+exit $Process.ExitCode