Skip to content

Instantly share code, notes, and snippets.

@ksasao
Created January 25, 2025 06:54
Show Gist options
  • Save ksasao/dc2540138e5e4b1e5674dad01105c6f4 to your computer and use it in GitHub Desktop.
Save ksasao/dc2540138e5e4b1e5674dad01105c6f4 to your computer and use it in GitHub Desktop.
Snipping Tool のインストールパスを取得する(Microsoft.ScreenSketch という名前でインストールされている)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FindSnippingToolPath
{
using System;
using System.Diagnostics;
using System.IO;
class Program
{
static void Main(string[] args)
{
string targetPath = GetSnippingToolPath();
if (string.IsNullOrEmpty(targetPath))
{
Console.WriteLine("Could not retrieve the target path.");
}
else
{
Console.WriteLine($"Target Path: {targetPath}");
}
}
static string GetSnippingToolPath()
{
// Snipping Tool は Microsoft.ScreenSketch という名前でインストールされている
string psCommand = $"(Get-AppxPackage -Name Microsoft.ScreenSketch).InstallLocation + '\\' + (Get-AppxPackage -Name Microsoft.ScreenSketch).AppInstallPath";
var psi = new ProcessStartInfo()
{
FileName = "powershell",
Arguments = $"-Command \"{psCommand}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (var process = Process.Start(psi))
{
using (var reader = process.StandardOutput)
{
string result = reader.ReadToEnd().Trim();
if (string.IsNullOrEmpty(result))
{
return string.Empty;
}
return result+"SnippingTool\\";
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment