情報もとはこちら,
http://support.microsoft.com/kb/2916013/ja
日本語がなかったので、英語32bitを入手した。
| OS | version | build | |
| Windows technical preview | 6.4 | 9841 | |
| Windows8.1 | 6.3 | 9600 | |
| Windows Server 2012 R2 | 6.3 | 9600 | |
| Windows8.1 Preview | 6.3 | 9431 | |
| Windows8 | 6.2 | 9200 | |
| Windows Server 2012 | 6.2 | 9200 | |
| Windows7 SP1 | 6.1 | 7601 | |
| Windows Server 2008 R2 SP1 | 6.1 | 7601 | |
| Windows7 | 6.1 | 7600 | |
| Windows Server 2008 R2 | 6.1 | 7600 | |
| Windows Vista SP2 | 6 | 6002 | |
| Windows Server 2008 SP2 | 6 | 6002 | |
| Windows Vista SP1 | 6 | 6001 | |
| Windows Server 2008 SP1 | 6 | 6001 | |
| Windows Vista | 6 | 6000 | |
| Windows Server 2008 | 6 | 6000 | |
| Windows XP | 5.1 | 2600 | |
@echo off for /L %%i in (1,1,10) do ( SET /P DUMMY="%date% , %time%," < nul tasklist /fi "imagename eq taskmgr.exe" /FO "CSV" /NH ping localhost -n 2 > nul )今まででてきていないことを2個使ってます。
@echo off setlocal enabledelayedexpansion for /L %%i in (1,1,10) do ( SET /P DUMMY="!date! , !time!," < nul tasklist /fi "imagename eq taskmgr.exe" /FO "CSV" /NH ping localhost -n 2 > nul )2行目を追加して、dateとtimeを!で囲んでいます。
HANDLE WinExists (
"title" // チェックする title/hWnd/class
[, "text"] // オプションの引数 ウィンドウのどっかにあるテキストと比較するみたい。
)
引数(title)と合致するウィンドウが存在して、かつ、activeかどうかを教えてくれる関数です。
bool WinActive(
"title" // チェックする title/class
)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//add
using System.Runtime.InteropServices;
using System.Collections;
using System.Text.RegularExpressions;
namespace AutoTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnWinExist_Click(object sender, EventArgs e)
{
bool bExists = WinExists( tBWinExistTitle.Text );
if (bExists)
{
// あった。
tBWinExistRet.Text = "Exist";
}
else
{
// なかった。
tBWinExistRet.Text = "Not Exist";
}
}
private void btnWinActive_Click(object sender, EventArgs e)
{
bool bRet = WinActive(tbWinActiveTitle.Text);
if (bRet)
{
// Active
tBWinActiveRet.Text = "Active";
}
else
{
// Not
tBWinActiveRet.Text = "Not";
}
}
//--------------------
// WindowのActiveかどうかの確認 細かくいうと、存在する かつ アクティブ
//--------------------
private bool WinActive(string title)
{
bool bret = false;
bool bExist = WinExists(title);
if (bExist)
{
// active な windowの情報を取得
IntPtr hWnd = Win32.GetForegroundWindow();
int size = Win32.GetWindowTextLength(hWnd);
if (size++ > 0 && Win32.IsWindowVisible(hWnd))
{
// ウィンドウタイトル
StringBuilder sbTitle = new StringBuilder(size);
Win32.GetWindowText(hWnd, sbTitle, size);
// class name
StringBuilder className = new StringBuilder(256);
Win32.GetClassName(hWnd, className, className.Capacity);
if (((sbTitle.ToString().IndexOf(title, StringComparison.OrdinalIgnoreCase)) >= 0)
|| ((className.ToString().IndexOf(title, StringComparison.OrdinalIgnoreCase)) >= 0))
{
bret = true;
}
}
}
return bret;
}
//--------------------
// Windowの存在確認
//--------------------
private bool WinExists(string title)
{
bool bret = false;
if (!title.Equals(string.Empty)) // 入力されなかったらやめる。
{
// 存在するウィンドウのタイトルとクラス名の一覧を取得
ArrayList alist = new ArrayList();
Win32.EnumWindows(new Win32.EnumWindowsProc(Win32.EnumTheWindows), ref alist);
// マッチするかチェック。
foreach (WndInfo winf in alist)
{
// titleとマッチするか?
if (winf.title.IndexOf(title, StringComparison.OrdinalIgnoreCase) >= 0)
{
bret = true;
break;
}
// クラス名とマッチするか?
if (winf.className.IndexOf(title, StringComparison.OrdinalIgnoreCase) >= 0)
{
bret = true;
break;
}
}
}
return bret;
}
}
//--------------------
// win32 api
//--------------------
public class Win32
{
// for Enumwindow
public delegate bool EnumWindowsProc(IntPtr hWnd, ref ArrayList data);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool EnumWindows(EnumWindowsProc enumProc, ref ArrayList data);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
// for getforegroundwnd
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public static bool EnumTheWindows(IntPtr hWnd, ref ArrayList alist)
{
int size = GetWindowTextLength(hWnd);
if (size++ > 0 && IsWindowVisible(hWnd))
{
// ウィンドウタイトル
StringBuilder sbTitle = new StringBuilder(size);
GetWindowText(hWnd, sbTitle, size);
// class name
StringBuilder className = new StringBuilder(256);
GetClassName(hWnd, className, className.Capacity);
alist.Add(new WndInfo(sbTitle.ToString(), className.ToString()));
}
return true;
}
}
//--------------------
// window の情報 を保持する 構造体
//--------------------
public struct WndInfo
{
public string title;
public string className;
public WndInfo(string Title, string ClassName)
{
title = Title;
className = ClassName;
}
}
}
bool WinExists (
"title" // チェックする title/hWnd/class
[, "text"] // オプションの引数 ウィンドウのどっかにあるテキストと比較するみたい。
)
bool WinExists (
"title" // チェックする title/class
)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//add
using System.Runtime.InteropServices;
using System.Collections;
using System.Text.RegularExpressions;
namespace AutoTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnWinExist_Click(object sender, EventArgs e)
{
bool bExists = WinExists( tBWinExistTitle.Text );
if (bExists)
{
// あった。
tBWinExistRet.Text = "Exist";
}
else
{
// なかった。
tBWinExistRet.Text = "Not Exist";
}
}
//--------------------
// これ。
//--------------------
private bool WinExists(string title)
{
bool bret = false;
if (!title.Equals(string.Empty)) // 入力されなかったらやめる。
{
// 存在するウィンドウのタイトルとクラス名の一覧を取得
ArrayList alist = new ArrayList();
Win32.EnumWindows(new Win32.EnumWindowsProc(Win32.EnumTheWindows), ref alist);
// マッチするかチェック。
foreach (WndInfo winf in alist)
{
// titleとマッチするか?
if (winf.title.IndexOf(title, StringComparison.OrdinalIgnoreCase) >= 0)
{
bret = true;
break;
}
// クラス名とマッチするか?
if (winf.className.IndexOf(title, StringComparison.OrdinalIgnoreCase) >= 0)
{
bret = true;
break;
}
}
}
return bret;
}
}
//--------------------
// win32 api
//--------------------
public class Win32
{
public delegate bool EnumWindowsProc(IntPtr hWnd, ref ArrayList data);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
protected static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
protected static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool EnumWindows(EnumWindowsProc enumProc, ref ArrayList data);
[DllImport("user32.dll")]
protected static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
public static bool EnumTheWindows(IntPtr hWnd, ref ArrayList alist)
{
int size = GetWindowTextLength(hWnd);
if (size++ > 0 && IsWindowVisible(hWnd))
{
// ウィンドウタイトル
StringBuilder sbTitle = new StringBuilder(size);
GetWindowText(hWnd, sbTitle, size);
// class name
StringBuilder className = new StringBuilder(256);
GetClassName(hWnd, className, className.Capacity);
alist.Add(new WndInfo(sbTitle.ToString(), className.ToString()));
}
return true;
}
}
//--------------------
// window の情報 を保持する 構造体
//--------------------
public struct WndInfo
{
public string title;
public string className;
public WndInfo(string Title, string ClassName)
{
title = Title;
className = ClassName;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//add
using System.Runtime.InteropServices;
using System.Collections;
namespace AutoTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ArrayList alist = new ArrayList();
Win32.EnumWindows(new Win32.EnumWindowsProc(Win32.EnumTheWindows), ref alist);
foreach (string str in alist)
{
label1.Text += str + Environment.NewLine;
}
}
}
public class Win32
{
public delegate bool EnumWindowsProc(IntPtr hWnd, ref ArrayList data);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
protected static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
protected static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool EnumWindows(EnumWindowsProc enumProc, ref ArrayList data);
[DllImport("user32.dll")]
protected static extern bool IsWindowVisible(IntPtr hWnd);
public static bool EnumTheWindows(IntPtr hWnd, ref ArrayList alist)
{
int size = GetWindowTextLength(hWnd);
if (size++ > 0 && IsWindowVisible(hWnd))
{
StringBuilder sb = new StringBuilder(size);
GetWindowText(hWnd, sb, size);
alist.Add(sb.ToString());
}
return true;
}
}
}