Compare commits

...

3 Commits

Author SHA1 Message Date
Muyuan Li (from Dev Box)
a3f8d78e4b Address review: quote template path and use full explorer.exe path
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-14 16:29:04 +08:00
copilot-swe-agent[bot]
c27534331b Fix: use explorer.exe explicitly to open NewPlus templates folder when running as different admin user
Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/481445da-c05e-4da6-af6c-07c83ecbf675

Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
2026-04-29 10:29:55 +00:00
copilot-swe-agent[bot]
aaadd5dd13 Initial plan 2026-04-29 08:51:05 +00:00
2 changed files with 46 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ViewModelTests
{
[TestClass]
public class NewPlus
{
[TestMethod]
public void CreateExplorerProcessStartInfoShouldQuoteTemplatePathAndUseFullExplorerPath()
{
// Arrange
const string templatePath = @"C:\Users\Test User\Documents\My Templates";
var createExplorerProcessStartInfoMethod = typeof(NewPlusViewModel).GetMethod("CreateExplorerProcessStartInfo", BindingFlags.NonPublic | BindingFlags.Static);
// Act
var processStartInfo = (ProcessStartInfo)createExplorerProcessStartInfoMethod.Invoke(null, new object[] { templatePath });
// Assert
Assert.IsNotNull(processStartInfo);
Assert.AreEqual(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe"), processStartInfo.FileName);
Assert.AreEqual($"\"{templatePath}\"", processStartInfo.Arguments);
}
}
}

View File

@@ -330,6 +330,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
private static readonly string ExplorerExePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
private bool _isNewPlusEnabled;
private string _templateLocation;
private bool _hideFileExtension;
@@ -356,12 +358,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
CopyTemplateExamples(_templateLocation);
var process = new ProcessStartInfo()
{
FileName = _templateLocation,
UseShellExecute = true,
};
Process.Start(process);
Process.Start(CreateExplorerProcessStartInfo(_templateLocation));
}
catch (Exception ex)
{
@@ -369,6 +366,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
private static ProcessStartInfo CreateExplorerProcessStartInfo(string templateLocation)
{
return new ProcessStartInfo
{
FileName = ExplorerExePath,
Arguments = $"\"{templateLocation}\"",
};
}
private async void PickNewTemplateFolder()
{
var newPath = await PickFolderDialog();