PowerShell, SetForegroundWindow, SendWait
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class FW {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
$hWnd =$null
$FGhWnd =$null
add-type -AssemblyName System.Windows.Forms
$process_list = get-process -Name powershell
foreach($process in $process_list){
$hWnd=$process.MainWindowHandle
[void][bool][FW]::SetForegroundWindow($hWnd)
Start-Sleep -m 10
$FGhWnd=[FW]::GetForegroundWindow()
if($hWnd -eq $FGhWnd){break}
}
if(($hWnd -eq $FGhWnd ) -and ( $hWnd-ne $null)){
[System.Windows.Forms.SendKeys]::SendWait("こんにちわ{ENTER}");
#[System.Windows.Forms.SendKeys]::SendWait("ipconfig{ENTER}");
"Sent"
}
$hWnd
$FGhWnd
$process.Name
$process.id
0 件のコメント:
コメントを投稿