// ProcessPrevInstance.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" #include "Form1.h" using namespace ProcessPrevInstance; using namespace System; static bool PrevInstance() { // このアプリケーションのプロセス名を取得 String^ sThisProcess = System::Diagnostics::Process::GetCurrentProcess()->ProcessName; // 同名のプロセスが他に存在した場合は、既に起動していると判断する if (System::Diagnostics::Process::GetProcessesByName(sThisProcess)->Length > 1) { return true; } // 存在しない場合は False を返す return false; } [STAThreadAttribute] int main(array ^args) { // 同名のプロセスが起動していない時は起動する if (!PrevInstance()) { // メイン ウィンドウを作成して、実行します Application::Run(gcnew Form1()); } return 0; }