diff --git a/Bin/set-telemetry.ps1 b/Bin/set-telemetry.ps1
index f4ea2ec6700..6e04c38793a 100644
--- a/Bin/set-telemetry.ps1
+++ b/Bin/set-telemetry.ps1
@@ -5,9 +5,19 @@ Param(
[bool]$telemetryEnabled = -not [string]::IsNullOrEmpty($Enabled);
+if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage")
+{
+ exit 0
+}
+
[string]$userAppDataPath = Join-Path -Path $env:APPDATA -ChildPath 'GitExtensions\GitExtensions\GitExtensions.settings'
if (-not (Test-Path -Path $userAppDataPath)) {
- '' | Out-File $userAppDataPath -Encoding utf8
+ [string]$userAppDataFolder = Split-Path $userAppDataPath -Parent
+ if (-not (Test-Path -Path $userAppDataFolder)) {
+ New-Item -ItemType Directory -Path $userAppDataFolder | Out-Null
+ }
+
+ '' | Out-File $userAppDataPath -Encoding utf8
}
[xml]$doc = Get-Content $userAppDataPath
@@ -32,6 +42,3 @@ $node = $doc.CreateElement('item');
$node.InnerXml = "TelemetryEnabled$telemetryEnabled";
$_ = $topNode.AppendChild($node);
$doc.Save($userAppDataPath)
-
-# this script now deletes itself
-Remove-Item $MyINvocation.InvocationName
diff --git a/Setup/UI/TelemetryDlg.wxs b/Setup/UI/TelemetryDlg.wxs
index 07374e96fcc..905ef62cbb6 100644
--- a/Setup/UI/TelemetryDlg.wxs
+++ b/Setup/UI/TelemetryDlg.wxs
@@ -14,11 +14,10 @@
-
+ Value=""[POWERSHELLEXE]" -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[INSTALLDIR]set-telemetry.ps1' [TELEMETRY_ENABLED]; exit $$($Error.Count)"" />