PowerShellの1行バッチでコンソールウィンドウを最小化/最大化/元に戻す。
コンソールウィンドウを最小化します。
PowerShell.exeの1行バッチを使えば、バッチファイルからそのコンソールウィンドウを最小化/最大化/元に戻すことができます。
以下は長いけれど1行です。
PowerShell.exe -command "$title=$Host.UI.RawUI.WindowTitle;$Host.UI.RawUI.WindowTitle+=(new-object random).next();$process=(ps|where {$_.MainWindowTitle -eq $Host.UI.RawUI.WindowTitle});$Host.UI.RawUI.WindowTitle=$title;$hwnd=$process.MainWindowHandle;[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');$message=[System.Windows.Forms.Message]::Create($hwnd,274,61472,0);$nativeWindow=new-object System.Windows.Forms.NativeWindow;$nativeWindow.DefWndProc([ref]$message);$nativeWindow=$null;"
コンソールウィンドウを最大化します。
PowerShell.exe -command "$title=$Host.UI.RawUI.WindowTitle;$Host.UI.RawUI.WindowTitle+=(new-object random).next();$process=(ps|where {$_.MainWindowTitle -eq $Host.UI.RawUI.WindowTitle});$Host.UI.RawUI.WindowTitle=$title;$hwnd=$process.MainWindowHandle;[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');$message=[System.Windows.Forms.Message]::Create($hwnd,274,61488,0);$nativeWindow=new-object System.Windows.Forms.NativeWindow;$nativeWindow.DefWndProc([ref]$message);$nativeWindow=$null;"
コンソールウィンドウを元に戻します。
PowerShell.exe -command "$title=$Host.UI.RawUI.WindowTitle;$Host.UI.RawUI.WindowTitle+=(new-object random).next();$process=(ps|where {$_.MainWindowTitle -eq $Host.UI.RawUI.WindowTitle});$Host.UI.RawUI.WindowTitle=$title;$hwnd=$process.MainWindowHandle;[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');$message=[System.Windows.Forms.Message]::Create($hwnd,274,61728,0);$nativeWindow=new-object System.Windows.Forms.NativeWindow;$nativeWindow.DefWndProc([ref]$message);$nativeWindow=$null;"
« コマンドラインからタスクスケジューラのタスクを終了する。 | トップページ | PowerShellからExcelオブジェクトを使う。 »