PowershellからWscript.Shellオブジェクトを利用して外部プログラムを実行
1 2 3 4 5 6 7 8 9 10 |
PS C:\> $WshShell = New-Object -ComObject WScript.Shell # メモ帳を起動 PS C:\> $WshShell.run("notepad.exe") 0 # メモ帳を最大化で起動してメモ帳が終了するまで待機 PS C:\> $WshShell.run("notepad.exe",3,$true) 0 # メモ帳を最大化で起動してすぐにshellに戻る PS C:\> $WshShell.run("notepad.exe",3,$False) 0 |
実行後にリターンコードが戻るようです
第2,第3パラメータについてはこちら
第5回 WshShellオブジェクトの詳細(1) (2/4)
http://www.atmarkit.co.jp/ait/articles/0407/08/news101_2.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PS C:\> New-Object -ComObject WScript.Shell | gm TypeName: System.__ComObject#{41904400-be18-11d3-a28b-00104bd35090} Name MemberType Definition ---- ---------- ---------- AppActivate Method bool AppActivate (Variant, Variant) CreateShortcut Method IDispatch CreateShortcut (string) Exec Method IWshExec Exec (string) ExpandEnvironmentStrings Method string ExpandEnvironmentStrings (string) LogEvent Method bool LogEvent (Variant, string, string) Popup Method int Popup (string, Variant, Variant, Variant) RegDelete Method void RegDelete (string) RegRead Method Variant RegRead (string) RegWrite Method void RegWrite (string, Variant, Variant) Run Method int Run (string, Variant, Variant) SendKeys Method void SendKeys (string, Variant) Environment ParameterizedProperty IWshEnvironment Environment (Variant) {get} CurrentDirectory Property string CurrentDirectory () {get} {set} SpecialFolders Property IWshCollection SpecialFolders () {get} |