防止同一个程序多次运行。
*****************方法一:防止程序多次打开*****************
函数名: isinstancerunning
功 能: 判断工程是否已运行
参 数: 无
返回值: true 已运行 false 未运行
*******************************************************
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
*****************方法二:防止程序多次打开*****************
imports system.diagnostics
if ubound(process.getprocessesbyname(process.getcurrentprocess.processname)) _
> 0 then eixt sub
process.getcurrentprocess.processname 获取当前运行程序的名称。
