防止同一個(gè)程序多次運(yùn)行。 '*****************方法一:防止程序多次打開(kāi)***************** ' 函數(shù)名: isinstancerunning ' 功 能: 判斷工程是否已運(yùn)行 ' 參 數(shù): 無(wú) ' 返回值: true 已運(yùn)行 false 未運(yùn)行 '******************************************************* public function isinstancerunning() as boolean dim current as process = system.diagnostics.process.getcurrentprocess() dim processes as process() = system.diagnostics.process.getprocessesbyname(current.processname) 'loop through the running processes in with the same name dim p as process for each p in processes 'ignore the current process if p.id <> current.id then 'make sure that the process is running from the exe file. if system.reflection.assembly.getexecutingassembly().location.replace("/", "/") = current.mainmodule.filename then 'return the other process instance. return true end if end if next 'no other instance was found, return null. return false end function 'runninginstance
'*****************方法二:防止程序多次打開(kāi)***************** imports system.diagnostics if ubound(process.getprocessesbyname(process.getcurrentprocess.processname)) _ > 0 then eixt sub 'process.getcurrentprocess.processname 獲取當(dāng)前運(yùn)行程序的名稱(chēng)。