Following Sub allows to ensure that only one instance of the script is running at time.

Usage:

Call EnsureSingleInstance

Code:

Sub EnsureSingleInstance()
dim svc, squery, ncount
set svc=getobject("winmgmts:root\cimv2")
    squery="SELECT commandline FROM win32_process WHERE commandline LIKE '%" & wscript.scriptname & "%'"
        ncount=svc.execquery(squery).count
    set svc=nothing
if ncount>1 then
' The script got executed more than once. Script EXIT!
wscript.quit
end if
End Sub

Kind Regards
Witold Lawacz (Ławacz)