This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4064 from golemfactory/install_as_admin
Install as admin
- Loading branch information
Showing
4 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |