ããã
https://tera1707.com/entry/2022/02/06/144447
ãããããã¨
UIã®ããwin32ã¢ããªã®ã¦ã¤ã³ãã¦ãæåé¢ã«æã£ã¦ããã®ã¯ãwin32APIã®SetForegroundWindow()
ã¨ããAPIã使ãã°ã§ãã¦ããã
ããUWPã¢ããªã¯ãã®æ¹æ³ã§ã¯ã§ããªãã£ãã
â»UWPã®ã¢ããªã¯ãApplicationFrameHost.exe
ã¨ããããã»ã¹ããå®ä½ã®exeï¼Windowsã®è¨å®ã®å ´åã¯SystemSettings.exe
ï¼ãå
ãã§ããï¼ï¼ããã«ãSystemSettings.exe
ã®ãã³ãã«ãåã£ã¦ãã¦SetForegroundWindow()ããã¦ããåé¢ã«åºã¦ãããªãã£ãã
ã¾ããApplicationFrameHost.exe
ã®ãã³ãã«ãåã£ã¦ãã¦SetForegroundWindow()ãããã¨ããç´åã«ãã©ã¼ã«ã¹ããã¦ãUWPã¢ããªã®ã¦ã¤ã³ãã¦ããæåé¢ã«ããã¨ããåãããã¦ãçã£ãUWPã®ã¦ã¤ã³ãã¦ãåé¢ã«æã£ã¦ãããªãã£ãã
ãªãã¨ããçã£ãUWPã¦ã¤ã³ãã¦ãåé¢ã«æã£ã¦ãããã
ãããã
Launcher.LaunchUriAsync()
ã¨
AppDiagnosticInfo
ã®LaunchAsync()
ã使ãã
ä»åã¯ãUWPã¢ããªï¼Windowsã®è¨å®ã¢ããªã§ãã£ã¦ã¿ãã
Windowsã®è¨å®ã¢ããªã¯ã
ms-settings:ãªãã¨ã
ã§ãéãããè¨å®ç»é¢ãæå®ãã¦éããã¨ãã§ããããã®ms-settings:ã使ã£ã¦ãä»åã¯ã
Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-webcam"))
ã§ãã«ã¡ã©è¨å®ç»é¢ãéãã¦ã- ãã®ç»é¢ãã
app.LaunchAsync()
ã§ãåã«ãã£ã¦ãã
ã¨ãããã¨ããã£ã¦ã¿ãã
å®é¨ã³ã¼ã
ä»åãUWPã®APIã使ãããã«ãã¿ã¼ã²ãããWindowsã«ãã¦ãã¿ã¼ã²ããã®OSã10.0.22000.0ã«ããã
using System; using System.Collections.Generic; using System.Threading; using Windows.System; using Windows.System.Diagnostics; namespace ProcessListUpByUwpApi; class Program { static async Task Main(string[] args) { while (true) { Console.WriteLine("å¦çã¹ã¿ã¼ã"); await LaunchSettingWindow(); Console.WriteLine("è¨å®ãéãã¾ãã"); await BringFront(); Console.WriteLine("è¨å®ãåã«æã£ã¦ãã¾ãã"); await Task.Delay(5000); } } static async Task LaunchSettingWindow() { // https://learn.microsoft.com/ja-jp/windows/uwp/launch-resume/launch-settings-app#calling-launchuriasync await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-webcam")); } static async Task BringFront() { var uwpApps = await AppDiagnosticInfo.RequestInfoAsync().AsTask(); if (uwpApps is null) return; var app = uwpApps.Where(x => x.AppInfo.AppUserModelId == "windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel") .FirstOrDefault(); if (app is null) return; // https://learn.microsoft.com/ja-jp/uwp/api/windows.system.appdiagnosticinfo.launchasync?view=winrt-26100 await app.LaunchAsync().AsTask(); } }
Windows è¨å®ã¢ããªã®èµ·å
ä¸è¨ã«ä¸è¦§ãããã