指定した文字列に当てはまるプロセス名やウインドウ名に当てはまるプロセスを強制終了させ、サインアウトするプログラムがあります。
下の場合、プロセス名やウインドウ名は完全一致しないと強制終了されません。
ワイルドカードで指定して強制終了させたいです。
youtubeという文字列が一つでも入るウインドウがあれば
listcount++されるといったことがしたいです。
たとえば、
ウインドウ名 (14) YouTube - Mozilla Firefox
→youtubeという文字列が入っているので listcount++
このようなコマンドをだれかご存知ではないですか。
(文字列は大文字小文字を区別しないとします)
プロセス名とウインドウ名2通りできたらお願いします。
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Diagnostics; 5using System.Linq; 6using System.Text; 7using System.Collections; 8using System.Threading.Tasks; 9 10namespace simultaneously_prohibited 11{ 12 public partial class NotifyIconWrapper : Component 13 { 14 public NotifyIconWrapper() 15 { 16 InitializeComponent(); 17 while (true) 18 { 19 int listcount = 0; 20 21 22 foreach (var p in Process.GetProcesses()) 23 if (p.MainWindowTitle == "無題 - メモ帳") 24 { 25 listcount++; 26 27 } 28 29 30 31 32 33 34 if (System.Diagnostics.Process.GetProcessesByName("chrome").Length > 0) 35 { 36 listcount++; 37 38 39 } 40 if (listcount >= 1) 41 { 42 ExitWindowsEx(ExitWindows.EWX_LOGOFF | ExitWindows.EWX_FORCE, 0); 43 44 } 45 46 47 // 1秒毎 48 System.Threading.Thread.Sleep(1000); 49 } 50 } 51 public enum ExitWindows : uint 52 { 53 EWX_LOGOFF = 0x00, 54 EWX_SHUTDOWN = 0x01, 55 EWX_REBOOT = 0x02, 56 EWX_POWEROFF = 0x08, 57 EWX_RESTARTAPPS = 0x40, 58 EWX_FORCE = 0x04, 59 EWX_FORCEIFHUNG = 0x10, 60 } 61 62 [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] 63 public static extern bool ExitWindowsEx(ExitWindows uFlags, 64 int dwReason); 65
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。