2022年5月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
無料ブログはココログ

« コマンドラインからタスクスケジューラのタスクを終了する。 | トップページ | PowerShellからExcelオブジェクトを使う。 »

2007年12月25日 (火)

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オブジェクトを使う。 »