經過我的測試,還比較好用,但是有個問題,如果不登出,用另乙個使用者進入,則程式不能判斷出已執行。所以只限於用在單使用者環境,還是不太完美。
classprogram
console.writeline(
"正在執行中");
console.readline();}}
public
static
class
oneinstance
return
ret;
}[dllimport(
"kernel32.dll
", charset =charset.auto)]
private
static
extern
intptr openmutex(
uint dwdesiredaccess, //
access
int binherithandle, //
inheritance option
string lpname //
object name
); [dllimport(
"kernel32.dll
", charset =charset.auto)]
private
static
extern
intptr createmutex(
intptr lpmutexattributes,
//sd
int binitialowner, //
initial owner
string lpname //
object name
); }
出處:
Delphi 防止程式多次執行
program project1 uses forms,windows,unit1 in unit1.pas var hmutex hwnd ret integer begin hmutex createmutex nil,false,test ret getlasterror if ret err...
防止程式多次執行(呼叫DLL)
region 防止程式多次執行 public abstract class oneinstance return ret dllimport kernel32.dll charset charset.auto private static extern intptr openmutex uint d...
Delphi實現防止程式多次執行
windows是個多使用者多工的作業系統,支援多個程式同時執行,如果你的程式不想讓使用者同時執行乙個以上,那應該怎樣做呢?本文將介紹避免使用者同時執行多個程式的例子。需要用到的函式createmutex createmutex 函式是windows中乙個並不常用的函式,該函式物件在系統中只能存在乙個...