Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4064 from golemfactory/install_as_admin
Browse files Browse the repository at this point in the history
Install as admin
  • Loading branch information
shadeofblue authored Apr 2, 2019
2 parents 6639857 + 7ae2fac commit 1ae76b7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
10 changes: 7 additions & 3 deletions Installer/Installer_Win/Golem.aip
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
<ROW BootstrOptKey="GlobalOptions" DownloadFolder="[AppDataFolder][|Manufacturer]\[|ProductName]\prerequisites" Options="2"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.BuildComponent">
<ROW BuildKey="DefaultBuild" BuildName="DefaultBuild" BuildOrder="1" BuildType="0" Languages="en_GB" InstallationType="2" CabsLocation="1" UseLzma="true" LzmaMethod="2" LzmaCompressionLevel="2" PackageType="1" FilesInsideExe="true" ExeIconPath="Installer\favicon.ico" ExtractionFolder="[AppDataFolder][|Manufacturer]\[|ProductName] [|ProductVersion]\install" ExtUI="true" UseLargeSchema="true" ExeName="golem-[|ProductVersion]-windows" MsiPackageType="x64" UACExecutionLevel="2"/>
<ROW BuildKey="DefaultBuild" BuildName="DefaultBuild" BuildOrder="1" BuildType="0" Languages="en_GB" InstallationType="2" CabsLocation="1" UseLzma="true" LzmaMethod="2" LzmaCompressionLevel="2" PackageType="1" FilesInsideExe="true" ExeIconPath="Installer\favicon.ico" ExtractionFolder="[AppDataFolder][|Manufacturer]\[|ProductName] [|ProductVersion]\install" ExtUI="true" UseLargeSchema="true" ExeName="golem-[|ProductVersion]-windows" MsiPackageType="x64"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.DictionaryComponent">
<ROW Path="&lt;AI_DICTS&gt;ui.ail"/>
Expand Down Expand Up @@ -406,7 +406,7 @@
<ROW Name="bannertop01.jpg" SourcePath="Installer\Installer_Win\banner-top-01.jpg"/>
<ROW Name="cleandockervm.ps1" SourcePath="scripts\docker\clean-docker-vm.ps1"/>
<ROW Name="lzmaextractor.dll" SourcePath="&lt;AI_CUSTACTS&gt;lzmaextractor.dll"/>
<ROW Name="preparedockerforwindows.ps1" SourcePath="scripts\docker\prepare-docker-for-windows.ps1"/>
<ROW Name="preparedockerasadmin.ps1" SourcePath="scripts\docker\prepare-docker-as-admin.ps1"/>
<ROW Name="tempFiles.dll" SourcePath="&lt;AI_CUSTACTS&gt;tempFiles.dll"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiConditionComponent">
Expand Down Expand Up @@ -468,7 +468,7 @@
<ROW Action="AI_DATA_SETTER_10" Type="51" Source="CustomActionData" Target="AEYAbABhAGcAcwACADMAAQBTAGMAcgBpAHAAdABTAHIAYwBCAGkAbgBhAHIAeQBSAG8AdwBJAGQAAgBjAGwAZQBhAG4AZABvAGMAawBlAHIAdgBtAC4AcABzADE="/>
<ROW Action="AI_DATA_SETTER_11" Type="51" Source="CustomActionData" Target="AEkAcwA2ADQAQgBpAHQAAgAxAAEAUABhAHIAYQBtAHMAAgABAFMAYwByAGkAcAB0AAIAQQBJAF8AUwBlAHQATQBzAGkAUAByAG8AcABlAHIAdAB5ACAASABZAFAARQBSAF8AVgBfAEEAVgBBAEkATABBAEIATABFACAAKABHAGUAdAAtAFcAbQBpAE8AYgBqAGUAYwB0ACAALQBxAHUAZQByAHkAIAAiAHMAZQBsAGUAYwB0ACAAKgAgAGYAcgBvAG0AIABXAGkAbgAzADIAXwBPAHAAdABpAG8AbgBhAGwARgBlAGEAdAB1AHIAZQAgAHcAaABlAHIAZQAgAG4AYQBtAGUAIAA9ACAAJwBNAGkAYwByAG8AcwBvAGYAdAAtAEgAeQBwAGUAcgAtAFYAJwAiACk="/>
<ROW Action="AI_DATA_SETTER_12" Type="51" Source="AI_RemoveAllTempFiles" Target="[AI_TEMP_FILE_ROLLBACK_INFO]"/>
<ROW Action="AI_DATA_SETTER_13" Type="51" Source="CustomActionData" Target="AEYAbABhAGcAcwACADMAAQBTAGMAcgBpAHAAdABTAHIAYwBCAGkAbgBhAHIAeQBSAG8AdwBJAGQAAgBwAHIAZQBwAGEAcgBlAGQAbwBjAGsAZQByAGYAbwByAHcAaQBuAGQAbwB3AHMALgBwAHMAMQ=="/>
<ROW Action="AI_DATA_SETTER_13" Type="51" Source="CustomActionData" Target="AEYAbABhAGcAcwACADMAAQBTAGMAcgBpAHAAdABTAHIAYwBCAGkAbgBhAHIAeQBSAG8AdwBJAGQAAgBwAHIAZQBwAGEAcgBlAGQAbwBjAGsAZQByAGEAcwBhAGQAbQBpAG4ALgBwAHMAMQ=="/>
<ROW Action="AI_DATA_SETTER_14" Type="51" Source="CustomActionData" Target="We have detected that you are trying to install Golem on Windows 10 Home. Unfortunately, your operating system does not support Hyper-V, but we have kept Docker Toolbox support.&#13;\n&#13;\nPlease download it manually from the official website https://docs.docker.com/toolbox/toolbox_install_windows/ in case you don&apos;t have it already installed on your computer. |Virtualization for Windows Home |MB_OK,MB_ICONINFORMATION,MB_DEFBUTTON1|BTN_PRESSED|[CLIENTPROCESSID]"/>
<ROW Action="AI_DATA_SETTER_16" Type="51" Source="CustomActionData" Target="Since 0.19.0 Golem supports Hyper-V.&#13;\n&#13;\nPlease be aware that if you are using any other virtualization software (e.g. Docker Toolbox, VMware) do not to install Hyper-V as this may cause issues with other applications on your system. &#13;\n&#13;\nBy clicking &quot;Yes&quot; you are agreeing for Hyper-V to be installed. Otherwise please make sure you have Docker Toolbox installed before running Golem. |Hyper-V in Windows Professional |MB_YESNO,MB_ICONINFORMATION,MB_DEFBUTTON1|INSTALL_HYPERV|[CLIENTPROCESSID]"/>
<ROW Action="AI_DATA_SETTER_2" Type="51" Source="StopProcess_Golemapp" Target="Golemapp.exe"/>
Expand Down Expand Up @@ -522,6 +522,7 @@
<ROW Action="SET_APPDIR" Type="307" Source="APPDIR" Target="[ProgramFilesFolder][Manufacturer]\[ProductName]" MultiBuildTarget="DefaultBuild:[ProgramFiles64Folder][ProductName]"/>
<ROW Action="SET_SHORTCUTDIR" Type="307" Source="SHORTCUTDIR" Target="[ProgramMenuFolder][ProductName]"/>
<ROW Action="SET_TARGETDIR_TO_APPDIR" Type="51" Source="TARGETDIR" Target="[APPDIR]"/>
<ROW Action="SetRunningUser" Type="51" Source="RUNNING_USER" Target="[%USERNAME]"/>
<ROW Action="StopProcess_DockerToolbox" Type="3073" Source="aicustact.dll" Target="StopProcess" Options="1" AdditionalSeq="AI_DATA_SETTER_4"/>
<ROW Action="StopProcess_Golem" Type="3073" Source="aicustact.dll" Target="StopProcess" Options="1" AdditionalSeq="AI_DATA_SETTER_1"/>
<ROW Action="StopProcess_Golemapp" Type="3073" Source="aicustact.dll" Target="StopProcess" Options="1" AdditionalSeq="AI_DATA_SETTER_2"/>
Expand Down Expand Up @@ -614,6 +615,7 @@
<ROW Action="AI_DATA_SETTER_11" Condition="( NOT Installed )" Sequence="51"/>
<ROW Action="MessageBox_DoYouWantHyperV" Condition="( NOT Installed ) AND ( HYPER_V_AVAILABLE &lt;&gt; &quot;&quot; )" Sequence="204"/>
<ROW Action="AI_DATA_SETTER_16" Condition="( NOT Installed ) AND ( HYPER_V_AVAILABLE &lt;&gt; &quot;&quot; )" Sequence="203"/>
<ROW Action="SetRunningUser" Condition="( NOT Installed )" Sequence="1299"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiLaunchConditionsComponent">
<ROW Condition="( Version9X OR ( NOT VersionNT64 ) OR ( VersionNT64 AND ((VersionNT64 &lt;&gt; 502) OR (ServicePackLevel &lt;&gt; 2) OR (MsiNTProductType &lt;&gt; 1)) AND ((VersionNT64 &lt;&gt; 502) OR (ServicePackLevel &lt;&gt; 2) OR (MsiNTProductType = 1)) AND ((VersionNT64 &lt;&gt; 600) OR (MsiNTProductType &lt;&gt; 1)) AND ((VersionNT64 &lt;&gt; 600) OR (MsiNTProductType = 1)) AND ((VersionNT64 &lt;&gt; 601) OR (MsiNTProductType &lt;&gt; 1)) AND ((VersionNT64 &lt;&gt; 601) OR (MsiNTProductType = 1)) AND ((VersionNT64 &lt;&gt; 602) OR (MsiNTProductType &lt;&gt; 1)) AND ((VersionNT64 &lt;&gt; 602) OR (MsiNTProductType = 1)) AND ((VersionNT64 &lt;&gt; 603) OR (MsiNTProductType &lt;&gt; 1)) AND ((VersionNT64 &lt;&gt; 603) OR (MsiNTProductType = 1)) AND ((VersionNT64 &lt;&gt; 1000) OR (MsiNTProductType &lt;&gt; 1) OR (WindowsBuild &lt;&gt; 10240)) AND ((VersionNT64 &lt;&gt; 1000) OR (MsiNTProductType &lt;&gt; 1) OR (WindowsBuild &lt;&gt; 10586)) AND ((VersionNT64 &lt;&gt; 1000) OR (MsiNTProductType &lt;&gt; 1) OR (WindowsBuild &lt;&gt; 14393)) AND ((VersionNT64 &lt;&gt; 1000) OR (MsiNTProductType &lt;&gt; 1) OR (WindowsBuild &lt;&gt; 15063)) ) )" Description="[ProductName] can not be installed on the following Windows versions: [WindowsTypeNT64Display]." DescriptionLocId="AI.LaunchCondition.NoSpecificNT64" IsPredefined="true" Builds="DefaultBuild"/>
Expand Down Expand Up @@ -690,6 +692,8 @@
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.TempFileComponent">
<ROW FileId="createshare.ps1" Name="CREATE~1.PS1|create-share.ps1" Directory_="version_Dir" Property="AI_CREATESHARE_FILE" Options="0" Data="scripts\docker\create-share.ps1"/>
<ROW FileId="preparedockerforwindows.ps1" Name="PREPAR~1.PS1|prepare-docker-for-windows.ps1" Directory_="version_Dir" Property="AI_PREPARE_DOCKER_FILE" Options="0" Data="scripts\docker\prepare-docker-for-windows.ps1"/>
<ROW FileId="runasadmin.ps1" Name="RUN-AS~1.PS1|run-as-admin.ps1" Directory_="version_Dir" Property="AI_RUN_AS_ADMIN_FILE" Options="0" Data="scripts\run-as-admin.ps1"/>
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.WinOptionalFeatureBundleComponent">
<ROW Name="HyperV" FeatureList="Microsoft-Hyper-V-Management-PowerShell,Microsoft-Hyper-V-Hypervisor,Microsoft-Hyper-V-Services,Microsoft-Hyper-V-Management-Clients" OSTargets="256" Condition="&amp;DockerForWin = 3" Flags="3"/>
Expand Down
21 changes: 21 additions & 0 deletions scripts/docker/prepare-docker-as-admin.ps1
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`""
20 changes: 2 additions & 18 deletions scripts/docker/prepare-docker-for-windows.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions scripts/run-as-admin.ps1
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

0 comments on commit 1ae76b7

Please sign in to comment.