using System; using System.Diagnostics; using System.Management; using System.ServiceProcess; namespace EMUtilCUI { class Program { static void Main(string[] args) { try { Console.WriteLine("D12LC用 Emobileユーティリティの無茶苦茶版"); Console.WriteLine("このプログラムを終了するに[Ctrl+C]を押してください"); // モデムが認識されている場合、終了する。 ServiceController modemSC = new ServiceController("Mobile Connector USB Device for Legacy Serial Communication LCT2053"); if (modemSC.Status == ServiceControllerStatus.Running) { Console.WriteLine("モデムはすでに認識されています。"); Console.WriteLine("終了します"); return; } // モデムがUSBドライブとして認識されているか確認する ManagementObjectSearcher modemDriveSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive Where Model = \"USBModem Disk USB Device\""); while (true) { if (0 < modemDriveSearcher.Get().Count) { break; } else { Console.WriteLine("D12LC(だかそのあたり)が見つかりません。"); Console.WriteLine("接続してENTERキーを押してください"); Console.ReadLine(); } } Console.WriteLine("D12LCが見つかりました"); // モデムとして認識させる Console.WriteLine("ユーティリティを起動します"); Process ps = new Process(); ps.StartInfo.FileName = "InstallDriver.exe"; ps.Start(); while (true) { modemSC.Refresh(); if (modemSC.Status == ServiceControllerStatus.Running) { Console.WriteLine("完了"); Console.WriteLine("モデムの認識を確認しました ユーティリティを終了します"); break; } else if(ps.HasExited) { Console.WriteLine("モデムが認識される前にユーティリティが終了しました。"); Console.WriteLine("ENTERキーを押すと再度ユーティリティを起動します"); Console.ReadLine(); ps.Start(); } Console.Write("."); System.Threading.Thread.Sleep(1000); } ps.Kill(); Console.WriteLine("正常に処理が完了しました\n終了します"); } catch (Exception) { Console.WriteLine("異常終了\n"); } } } }