PowerShell は、C# のコードをそのまま実行する事ができるので、MesaageBox を表示させて、そまの応答結果をファイルに書き込んで、バッチファイル内の for で読み込み、内容によって実行先を変化させます console_message_box.ps1
$code = @"
using System;
using System.IO;
using System.Windows.Forms;
public class MyClass {
public static void console_message_box() {
string path = Environment.GetEnvironmentVariable("temp");
string writePath = string.Format(@"{0}\_check_result",path);
StreamWriter sw = new StreamWriter(writePath,false);
DialogResult check = MessageBox.Show("実行しますか?","確認", MessageBoxButtons.OKCancel);
if (check == DialogResult.OK)
{
sw.Write("1");
}
else
{
sw.Write("0");
}
sw.Close();
}
}
"@
Add-Type -Language CSharp -TypeDefinition $code -ReferencedAssemblies ("System.Windows.Forms")
[MyClass]::console_message_box()
inter_active.bat
echo off echo 処理を開始しました powershell -NoProfile -ExecutionPolicy Unrestricted .\console_message_box.ps1 FOR /F %%i IN (%temp%\_check_result) DO ( if "%%i"=="1" goto :ok if "%%i"=="0" goto :cancel ) :ok echo OK を選択しました goto :end :cancel echo Cancel を選択しました goto :end :end
関連する記事 PowerShell : ファイルを開くダイアログを使うのに System.Windows.Forms を参照する二つの方法 バッチファイル内で、コマンドプロンプトが管理者権限で実行されているかのチェック
|
|
【PowerShell + C#の最新記事】
- nuget.exe CLI を使用してパッケージをダウンロードし、C# のソースコードで利用して PowerShell でビルドする
- PowerShell を使用して、C# のコンソールアプリ用のソースコードから exe を作成する( WebClient で wget.exe ) / ビルドせずに PowerShell で実行
- PowerShell で VisualStudio で作成した Form アプリケーションをビルドする( DataGridView に select 文の結果を表示する / MySQL )
- PowerShell で VisualStudio で作成した Form アプリケーションをビルドする( Form アプリケーションを テキストエディタのみで作成するテンプレート )
- TKMP + imap + C# + PowerShell : メールボックス(階層)の一覧表示
- nuget.exe + SMO + PowerShell + C# : テーブルの CREATE TABLE 文 を取得
- PowerShell( 実質C# )を使用して、ファイルの分割を行う
- PowerShell で C# のソースコード(get_rec_mysql.cs) を使用して System.Data.Odbc で MySQL のデータを一覧表示( csv )






