æŸèæ
ãã¹ãŠã®è¯ãäžæ¥ã WSH VBScriptã®ãã«ãã¹ã¬ããïŒãŸãã¯ããã«ãããã»ãã·ã³ã°ãïŒã®ã¡ã«ããºã ãå®è£ ããæŸèæãæäŸããŸãã ã€ã³ãã³ãŒãã«ã¢ã¬ã«ã®ãŒã®ãã人ã«ã¯ãå§ãããŸããã
ãã«ãã¹ã¬ããã®æœåšçãªå©äŸ¿æ§ã«ã€ããŠæåã«èããã®ã¯ãæ å ±ãåŠçããŠèŠèŠåãããšããæ¯èŒçåçŽãªã¿ã¹ã¯ã«é¢ããèªçºçãªæ±ºå®ã®éã«äžåºŠæ¥ãŸããã ãŸããVisual Studioãšãã«ããã¹ã¯ã®ãããªIDEã®ã€ã³ã¹ããŒã«ã¯äºææ§ã®ãªãæŠå¿µã§ãããããVBAãšWSHã®ã¿ããåæ³çãªããã®ãšããŠæ®ããŸããã ãã®æãåŸè ãéžã°ããŸããã ãããŠãçŸåšã®ç®¡çäžã®å¶éãšäœ¿ããããã¡ãœãããååŸããããšããèŠæã«ããããã®ãã«ãããã»ãã·ã³ã°ã®å®è£ ã®èŠä»¶ã決ãŸããŸããã
- ã³ãŒãã¯ãéåžžã®ã¹ã¯ãªããã®ããã«åäžã®ãã¡ã€ã«ã«ãããŸãã
- WSH x86 / x64ã§ã¯ãæå°éã®ActiveXã䜿çšããWMIãªãã§æ©èœããã®ã¯çµã¿èŸŒã¿ã®ã¿ã§ãã
- é床ãšãã¿ãŒã³ããããååãªæ©èœãšå©äŸ¿æ§ãéèŠã§ãã
æ©èœïŒ
- èµ·åãããã¹ã¯ãªããã¯ãµãŒãã¹æ©èœãå®è¡ããŸãã ã¡ã€ã³ã³ãŒãã¯åŸç¶ã®ããã»ã¹ã§å®è¡ãããŸãã
- ããã«ããŒãžã§ã³ãã§ã¯ãã¡ã€ã³ã³ãŒãã¯ã¯ã©ã¹ã«ã®ã¿é 眮ããããã®ããããå¥ã®ããã»ã¹ã§ã€ã³ã¹ã¿ã³ã¹åã§ããŸãã æ°ããããã»ã¹ããšã«ãã¹ã¯ãªããã¯ãŠãŒãã£ãªãã£ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããæå®ãããã¿ãŒã²ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããã¿ãŒã²ããã¡ãœãããåŒã³åºãããã®é²è¡ãå¶åŸ¡ããäœæãããã¯ã©ã¹ã€ã³ã¹ã¿ã³ã¹ãåç §ããã°ããŒãã«ã¹ã¯ãªããã³ã³ããã¹ãã«å€æ°ãäœæããŸãã åæåãããã¿ãŒã²ããã¯ã©ã¹ã®ãªããžã§ã¯ãã¯åã®ã¹ã¯ãªããã«è¿ãããå®è¡äžã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¯ã©ã¹ã®åæåãšå®äºã®ã€ãã³ãã¯ãåŠçããããŸãã
- ãã©ã€ãããŒãžã§ã³ãã§ã¯ãããžãã¯ã¯äŒŒãŠãããã¡ã€ã³ã³ãŒãã®ã¿ãsub'ovå ã«é 眮ããããªããžã§ã¯ãã¯åã®ã¹ã¯ãªããã«è¿ããããèµ·åããããã®ã®ã€ã³ããã¯ã¹ã«ãªããã€ãã³ãåŠçã¯ãããŸããã
- æ°ããããã»ã¹ãäœæããããã«ãã¹ã¯ãªããã¯ããèªäœãååž°çã«èµ·åããåŒã³åºãããã¡ãœããã«é¢ããããŒã¿ãæž¡ããååä»ãåŒæ°ã®æ å ±ãèå¥ããŸãã
- åäžã®å®è¡ã¹ããŒã¹ã¯ãªããåã¹ã¯ãªããã¯ãã®ããŒã¿ãšãªããžã§ã¯ããã³ã³ããã¹ãã«ä¿åããŸãã ããŒã¿ã亀æããã«ã¯ãGrayãã©ãŒã©ã ã®ãããã¯ãã¹ã¯ãªããéã§ã®ããŒã¿ãšãªããžã§ã¯ãã®äº€æ-2ãã§èª¬æãããŠããGlobalContainerã䜿çšããŠãæåã®ã¹ã¯ãªããã®Meãªããžã§ã¯ããåŸç¶ã®ãã®ã«è»¢éãããŸã ã ã¿ãŒã²ããã¡ãœããã®å®äºåŸã®åã¹ã¯ãªããã¯ãèš±å¯ãå®äºããããšãæåŸ ããŠããŸãããã®ãããªé 延ã«ãããåä¿¡ããæ å ±ãååŸã§ããŸãã
- WSH WScriptãšCScriptã§åãããã«æ©èœããScriptCryptorã§ã³ã³ãã€ã«ãããexeãã¡ã€ã«ã®åœ¢åŒã§æ©èœããŸãïŒãã ããclass_terminateã¡ãœããã¯exeã§ã¯æ©èœããŸããïŒã
çæïŒ
- onãšã©ãŒã®äœ¿çšã«ãããããã°ã®é£ããã¯æ¬¡ã«åéãããå€ãã®æ¹æ³ã§å®è¡ãããŸãã ãã¹ãŠåãã§ãããããã¯æŸèæã§ãã
- ããã°ãã
- ã¹ã¯ãªããã®å®äºé åºã¯å®å šã«éçºè ã®è²¬ä»»ã§ãã åœç¶ãå®äºããã¹ã¯ãªããã®ãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ãããšãšã©ãŒãçºçããŸãã
å®éïŒ
- ã¡ãœãããè€æ°ã®ããã»ã¹ã䜿çšã§ããªãããã«ããããã®mutexãšã¡ã«ããºã ã¯å®è£ ãããŠããŸããã
- ä»ã®ã³ã³ããã¹ãããã¹ã¯ãªããå€æ°ã«ã¢ã¯ã»ã¹ããŠãããšãã«é害ãçºçããå ŽåããããŸãã
- CScript.exeã³ã³ãœãŒã«ãŠã£ã³ããŠãéããŠãããšã¯ã¹ãããŒã©ãŠã£ã³ããŠã¯ã¡ã¢ãªã«æ®ããŸãã
mproclite.vbsã®ã©ã€ãããŒãžã§ã³ïŒ
option explicit launch "base" ' main programm section sub base() startproc "msg" startproc "msg" startproc "msg" msgbox "base, id = " & id, 64 free id end sub sub msg() msgbox "msg, id = " & id, 64 free id end sub ' do not modify service section sub launch(byval destination) dim job executeglobal "dim scene, container, signature, subname, jobs, id, state, release" release = false if not wscript.arguments.named.exists("task") then dim elt executeglobal "dim found, lost" id = 0 found = 0 lost = 0 signature = "" randomize do signature = signature & hex(rnd * 16) loop while len(signature) < 16 set scene = me set jobs = createobject("Scripting.Dictionary") set jobs(0) = scene set container = getobject("new:{C08AFD90-F2A1-11D1-8455-00A0C91F3880}") container.putproperty signature, scene startproc destination on error resume next do until (lost >= found) or release for elt = found to 1 step -1 if typename(jobs(elt)) = "Object" then lost = lost + 1 jobs(elt) = empty end if err.clear wscript.sleep 1 next loop release = true executeglobal "scene_beforeterminate" for elt = found to 1 step -1 if typename(jobs(elt)) = "VBScriptTypeInfo" then jobs(elt).wscript.timeout = 1 jobs(elt).wscript.quit err.clear nojobs = false end if wscript.sleep 1 next container.quit else job = split(wscript.arguments.named("task"), ";") signature = cstr(job(0)) id = clng(job(1)) subname = cstr(job(2)) do for each container in createobject("Shell.Application").windows if isobject(container.getproperty(signature)) then exit do end if next wscript.sleep 1 loop set scene = container.getproperty(signature) set jobs = scene.jobs state = 4 set jobs(id) = me executeglobal subname state = 24 do until release wscript.sleep 10 loop state = 28 end if end sub function startproc(subname) startproc = createproc(subname) joint startproc, 4, 0 REM do while getstate(startproc) < 4 REM wscript.sleep 10 REM loop end function function createproc(subname) if me is scene then if not release then found = found + 1 createproc = found set jobs(createproc) = nothing createobject("WScript.Shell").exec("""" & wscript.fullname & """ """ & wscript.scriptfullname & """ ""/task:" & join(array(signature, createproc, subname), ";") & """") end if else createproc = scene.createproc(subname) end if end function function getjob(target) on error resume next if jobs.exists(target) then set getjob = jobs(target) if err.number = 0 then exit function err.clear end if set getjob = nothing end function sub share(varname, value) scene.newvar varname if isobject(value) then execute "set scene." & varname & " = value" else execute "scene." & varname & " = value" end if end sub sub newvar(varname) executecommand "dim " & varname end sub sub executecommand(command) executeglobal command end sub function getstate(target) dim elt if jobs.exists(target) then on error resume next set elt = jobs(target) getstate = elt.state if err.number <> 0 then if not(elt is nothing) then getstate = 64 else getstate = 1 end if end if set elt = nothing else getstate = 64 end if end function function isresponsive(target) isresponsive = cbool(getstate(target) and 28) end function sub free(target) if jobs.exists(target) then on error resume next jobs(target).release = true else dim elt, subname for elt = scene.found to 1 step -1 on error resume next subname = jobs(elt).subname if subname = target then free jobs(elt).id end if err.clear next end if end sub function joint(target, state, timeout) dim reftime reftime = timer on error resume next if jobs.exists(target) then if isnumeric(target) then do while getstate(target) < state if timeisout(timeout, reftime) then joint = false exit function end if wscript.sleep 10 loop else dim elt, subname for elt = scene.found to 1 step -1 subname = jobs(elt).subname err.clear if subname = target then do while getstate(target) < state if timeisout(timeout, reftime) then joint = false exit function end if wscript.sleep 10 loop end if err.clear next end if end if joint = true end function function timeisout(timeout, reftime) if timeout > 0 then dim delta delta = timer - reftime if delta < 0 then delta = delta + 86400 if delta > timeout then timeisout = true end if else timeisout = false end if end function sub interrupt(target, timeout) if jobs.exists(target) then on error resume next jobs(target).wscript.timeout = timeout jobs(target).wscript.quit else dim elt, subname for elt = scene.found to 1 step -1 on error resume next subname = jobs(elt).subname if subname = target then interrupt jobs(elt).id end if err.clear next end if end sub sub push(name, value) container.putproperty name, value end sub function pop(name) on error resume next if isobject(container.getproperty(name)) then set pop = container.getproperty(name) else pop = container.getproperty(name) end if end function
説æïŒ
ã©ã€ãããŒãžã§ã³ã®ãã«ãããã»ãã·ã³ã°ã¡ã«ããºã æ©èœïŒ
ãµãããŒã ãèµ·å
ãµãŒãã¹ã¢ã«ãŽãªãºã ãèµ·åããã¹ã¯ãªããã®å®è¡ã¯åžžã«ãã®åŒã³åºãããå§ãŸããŸãã
subnameã¯ãæ°ããããã»ã¹ã§å®è¡ãããã¿ãŒã²ããsubã瀺ãæååã§ãã
ãã®ã¡ãœããã®åŒæ°ã¯ãã¡ã€ã³ã³ãŒãã®å®è¡ãéå§ããããã«æåã«èµ·åãããã¹ã¯ãªããã§ã®ã¿äœ¿çšãããŸãã
æ°ããåã¹ã¯ãªããã§ïŒ
- å€æ°ã¯ãå®è¡äžã®ã¹ã¯ãªããã®ã°ããŒãã«ã¹ããŒã¹ã§å®£èšãããŸãã
scene-æåã®ã¹ã¯ãªããã®Meãªããžã§ã¯ããžã®åç §ã
container -GlobalContainerãšã¯ã¹ãããŒã©ãŒãŠã£ã³ããŠãžã®ãªã³ã¯ã
signature -GlobalContainerãèå¥ããããã«çæãããæååã
èŠã€ãã£ãã倱ããã -ã·ãŒã³ã®ã¿-äœæããã³å®äºããã¹ã¯ãªããããã»ã¹ã®æ°ã
subname-æååãã¹ã¯ãªããã®ç®çãå«ãã
jobs-ã·ãŒã³ã§äœæãããå®è¡ã¹ã¯ãªããã®Meãªããžã§ã¯ããå«ãèŸæžãžã®ãªã³ã¯ã
id-ãã®ã¹ã¯ãªããã®ã·ãªã¢ã«çªå·-èŸæžã®ããŒã
release = False-ã¿ãŒã²ããsubãå®äºãããšãTrueãå²ãåœãŠãåŸã«ã¹ã¯ãªãããå®äºããŸãã
state = 4-ãã®ã¹ã¯ãªãããé 眮ãããŠããç¶æ ã - ã¢ã€ãã ããžã§ããã£ã¯ã·ã§ããªã«è¿œå ãããŸãã
startproc ïŒãµãããŒã ïŒ
ãµãããŒã -launchïŒïŒãåç §ããŠãã ããã
æ°ããã¹ã¯ãªããããã»ã¹ãäœæããã¹ã¯ãªããã®Meãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ã§ãããšãã«ãç¶æ 4ïŒgetstateïŒïŒãåç §ïŒã®æºåãæŽããŸã§åŸ æ©ããŸãã å®è¡äžã®ã¹ã¯ãªããã®ID-IDãè¿ããŸãã
createproc ïŒãµãããŒã ïŒ
ãµãããŒã -launchïŒïŒãåç §ããŠãã ããã
åŸ æ©ããããšãªããæ°ããã¹ã¯ãªããããã»ã¹ãäœæããæ°å€-å®è¡äžã®ã¹ã¯ãªããã®IDãè¿ããŸãã åããã»ã¹ã®æºåãæŽãã®ãåŸ ããã«ãã«ãŒãã§è€æ°ã®ããã»ã¹ãéåæçã«äœæããããã«äœ¿çšããŸãã ãã®ãããªã¢ããªã±ãŒã·ã§ã³ã§startprocïŒïŒã䜿çšãããããèããé«éã§ãã
getjob ïŒã¿ãŒã²ããïŒ
target-äœæãããã¹ã¯ãªããã®ã°ã«ãŒãã®çªå·ãã¹ã¯ãªããIDãŸãã¯æååããµãããŒã ã
Meã¹ã¯ãªãããªããžã§ã¯ããžã®ã¢ã¯ã»ã¹ãæäŸããŸãã idãèŠã€ãããªãããã¹ã¯ãªãããå®äºããå Žåãã¹ã¯ãªããã®Meãªããžã§ã¯ããžã®åç §ãè¿ããŸã-Nothingã
getstate ïŒã¿ãŒã²ããïŒ
target-ã¹ã¯ãªããã®çªå·ãIDã
ã¹ã¯ãªããã®ç¶æ ã決å®ããŸãã æ°å€ãå®è¡ã¹ããããè¿ããŸãã
1ã€ã®ããã»ã¹ãäœæãããŸããïŒæ°ããããã»ã¹execïŒã
4ã¹ã¯ãªãããå®è¡äžïŒåæåæžã¿ïŒã
24åã®ã¿ãŒã²ãããµããå®äºããŸãã
28åã®ã¹ã¯ãªããããªãªãŒã¹ãããŸãã
64ãèŠã€ãããŸããïŒãã¹ããèŠã€ãããŸããïŒãã¹ã¯ãªããã¯çµäºããŸããã
isresponsive ïŒã¿ãŒã²ããïŒ
ã¿ãŒã²ãã-getstateïŒïŒãåç §ããŠãã ããã
Meã¹ã¯ãªãããªããžã§ã¯ãã®å¯çšæ§ã決å®ããŸãïŒç¶æ 4ã28ïŒã ããŒã«å€ãè¿ããŸãã
executecommandã³ãã³ã
commandã¯æ瀺ãå«ãæååã§ãã
ã€ã³ã¿ãŒããªã¿ãŒãåŒã³åºããŠãã°ããŒãã«ã¹ã¯ãªããã¹ããŒã¹ã§ã¹ããŒãã¡ã³ããå®è¡ããŸãã
varnameãvalueãå ±æããŸã
varnameã¯å€æ°ã®ååãå«ãæååã§ãvalueã¯ä»»æã®å€ã§ãã
æåã®ã¹ã¯ãªããã®ã°ããŒãã«ã¹ããŒã¹ã§varnameãšããååã®å€æ°ã宣èšããŸããããã¯ãã·ãŒã³ããããã£ã®åœ¢åŒã§ãã¹ãŠã®ã¹ã¯ãªããã§äœ¿çšå¯èœã«ãªããvalueã®å 容ãå€æ°ã«å²ãåœãŠãŸãã
newvar varname
varnameã¯ãå€æ°ã®ååãå«ãæååã§ãã
ã°ããŒãã«ã¹ã¯ãªããã¹ããŒã¹ã§æ°ããå€æ°ã宣èšããŸãã
ç¡æã®ã¿ãŒã²ãã
target-äœæãããã¹ã¯ãªããã®ã°ã«ãŒãã®çªå·ãã¹ã¯ãªããIDãŸãã¯æååããµãããŒã ã ã¿ãŒã²ããsubã®å®è¡åŸãã¹ã¯ãªããã®çµäºãèš±å¯ããŸãã åäžã®ã¹ã¯ãªãããŸãã¯ã°ã«ãŒãã§åäœããŸãã
ãžã§ã€ã³ã ïŒã¿ãŒã²ãããç¶æ ãã¿ã€ã ã¢ãŠãïŒ
target-freeïŒïŒãåç §ãstate-getstateïŒïŒãåç §ãtimeout-ããªç§åäœã®ç§åäœã®æ°å€ã
ç¶æ ã¹ã¯ãªãããå°çãããŸã§åŸ æ©ããŸããã¹ã¯ãªããã®ã°ã«ãŒãã§ã¯ããããããç¶æ ã«å°éãããŸã§åŸ æ©ããŸãã åŸ æ©ã¯ã¿ã€ã ã¢ãŠãã«ãã£ãŠå¶éãããŸããã¿ã€ã ã¢ãŠã= 0ã¯ç¡å¶éã®åŸ æ©ãæå³ããŸãã ããŒã«å€ãTruth-åŸ æ©ã¯çµäºãFalse-ã¿ã€ã ã¢ãŠããè¿ããŸãã ã¹ã¯ãªãããåæããããã«èšèšãããŠããŸãã ããšãã°ãã¹ã¯ãªãããéå§ãããŸã§åŸ ã€å¿ èŠãããå Žå-4ãã¹ã¯ãªããã¯å®äºããŸã-64ã
å²ã蟌ã¿ã¿ãŒã²ãããã¿ã€ã ã¢ãŠã
ã¿ãŒã²ãã-freeïŒïŒãã¿ã€ã ã¢ãŠã-ç§åäœã®wscript.timeoutã®å€ãåç §ããŠãã ããã
class_terminateã¡ãœããã®å®è£ ã«ãããã¹ã¯ãªãããéåžžã®å®äºã«å€æããŸãã ã¹ã¯ãªããã§ãã€ã¢ãã°ããã¯ã¹ãéãããå Žåãã¿ã€ã ã¢ãŠãã®äžæåæ¢åŸã«ã®ã¿å®äºããŸãã class_terminateã¡ãœããã§ãã€ã¢ãã°ããã¯ã¹ãå衚瀺ãããšãå®äºãåæ¢ããŸãã
ããã·ã¥åãå€
name-æååãããããã£åãvalue-ä»»æã®å€ã
nameãšããååã®GlobalContainerããããã£ã«valueã®å 容ãå ¥ããŸãã
ããã ïŒååïŒ
name-æååãããããã£åã
GlobalContainerããnameãšããååã®ããããã£ã®å 容ãè¿ããŸãã
mproc.vbsã®ãã«ããŒãžã§ã³ïŒ
option explicit dim mproc set mproc = new multiprocess mproc.launch "base", "run", "" ' main programm section class base public sub run() host.startproc "msg", "run", "first" host.startproc "msg", "run", "second" host.startproc "msg", "run", "third" msgbox "base, id = " & host.id, 64 host.free host.id end sub end class class msg public sub run() msgbox host.aliasname & ", id = " & host.id, 64 host.free host.id end sub end class ' do not modify service class section class multiprocess public primary, ancestor, parent, process, err public names, execs, hosts public id, aid, isprimary public classname, methodname, aliasname public found, lost, active public state, permit, release private container, signature, wshshell public sub launch(startclassname, startmethodname, startaliasname) permit = false release = false executeglobal "dim scene, host, ancestor, process" if not isempty(host) then exit sub set host = me executeglobal "set host.err = err" executeglobal "function getroot: set getroot = me: end function" set parent = getroot isprimary = not wscript.arguments.named.exists("task") if isprimary then dim sample state = 24 randomize signature = "" do signature = signature & hex(rnd * 16) loop while len(signature) < 16 aid = empty id = 0 found = 0 lost = 0 set wshshell = createobject("WScript.Shell") set primary = host set ancestor = nothing set process = nothing set scene = parent set parent.ancestor = nothing set parent.process = nothing set hosts = createobject("Scripting.Dictionary") set execs = createobject("Scripting.Dictionary") set names = createobject("Scripting.Dictionary") classname = empty methodname = empty aliasname = empty set hosts(0) = host set container = getobject("new:{C08AFD90-F2A1-11D1-8455-00A0C91F3880}") container.putproperty signature, parent startproc startclassname, startmethodname, startaliasname on error resume next do for each sample in execs.keys if release or active = 0 then exit do if not (execs(sample) is nothing) then if execs(sample).status > 0 then abolish sample end if end if wscript.sleep 1 next loop release = true state = 28 scenequit else dim job job = split(wscript.arguments.named("task"), ";") signature = cstr(job(0)) do for each container in createobject("Shell.Application").windows if isobject(container.getproperty(signature)) then exit do end if next wscript.sleep 1 loop aid = clng(job(1)) id = clng(job(2)) found = null lost = null set scene = container.getproperty(signature) set primary = scene.host set hosts = primary.hosts set ancestor = hosts(aid) if isresponsive(aid) then set parent.ancestor = ancestor.parent.process else set parent.ancestor = nothing end if classname = cstr(job(3)) methodname = cstr(job(4)) aliasname = cstr(job(5)) state = 4 primary.implicate id, aliasname, host executeglobal "set process = new " & classname executeglobal "set host.process = process" executeglobal "set scene." & aliasname & " = process" if isresponsive(aid) then executeglobal "set host.ancestor.parent." & aliasname & " = process" end if state = 8 primary.staff host ancestorevent "oninitialized" state = 12 if methodname <> "" then do until permit wscript.sleep 10 loop state = 16 executeglobal "process." & methodname end if state = 20 ancestorevent "oncompleted" state = 24 do until release wscript.sleep 10 loop state = 28 end if end sub public default function startproc(classname, methodname, aliasname) set startproc = start(createproc(classname, methodname, aliasname)) end function public function createproc(classname, methodname, aliasname) if aliasname = "" then aliasname = classname newvar aliasname scene.host.newvar aliasname createproc = primary.spawn(id, classname, methodname, aliasname) end function public function spawn(issuer, classname, methodname, aliasname) if not release then found = found + 1 spawn = found active = found - lost names(spawn) = aliasname set hosts(spawn) = nothing if not hosts.exists(aliasname) then hosts.add aliasname, createobject("Scripting.Dictionary") end if set hosts(aliasname)(spawn) = nothing execs.add spawn, wshshell.exec("""" & wscript.fullname & """ """ & wscript.scriptfullname & """ ""/task:" & join(array(signature, issuer, spawn, classname, methodname, aliasname), ";") & """") end if end function public function start(target) select case outline(target) case "Nothing", "multiprocess" do while getstate(target) < 12 wscript.sleep 10 loop if isresponsive(target) then set start = hosts(target).process hosts(target).permit = true else set start = nothing end if case "Dictionary" dim elt set start = hosts(target) for each elt in start.keys do while getstate(elt) < 12 wscript.sleep 10 loop next for each elt in start.keys if isresponsive(elt) then hosts(elt).permit = true end if next case else set start = nothing end select end function public sub implicate(id, aliasname, host) set hosts(aliasname)(id) = host set hosts(id) = host end sub public sub staff(host) set hosts(host.process) = host end sub public sub abolish(id) if hosts.exists(names(id)) then hosts(names(id))(id) = empty end if names(id) = empty if isresponsive(id) then hosts(hosts(id).process) = empty end if hosts(id) = empty set execs(id) = nothing lost = lost + 1 active = found - lost end sub private sub ancestorevent(eventname) if aid > 0 then on error resume next executeglobal "ancestor." & aliasname & "_" & eventname & " host.hosts(" & id & ")" if err.number = 424 or err.number = 438 then err.clear end if end sub public sub assignhandler(handlername, byval varsqty) dim vars vars = "" if varsqty > 0 then do vars = vars & "param" & varsqty varsqty = varsqty - 1 if varsqty = 0 then exit do vars = vars & ", " loop end if executeglobal "sub " & handlername & "(" & vars & "): process." & handlername & " " & vars & ": end sub" end sub public sub newvar(varname) executecommand "dim " & varname end sub public sub executecommand(command) executeglobal command end sub public function getstate(target) select case outline(target) case "multiprocess" on error resume next getstate = hosts(target).state if err.number <> 0 then err.clear getstate = 64 end if case "Nothing" getstate = 1 case "Dictionary" getstate = null case empty getstate = 0 case else getstate = 64 end select end function private function outline(target) on error resume next if hosts.exists(target) then outline = typename(hosts(target)) if err.number <> 0 then err.clear outline = "Object" end if else outline = empty end if end function public function isresponsive(target) isresponsive = cbool(getstate(target) and 28) end function public function getid(target) on error resume next if isobject(target) then if isresponsive(target) then getid = hosts(target).id if err.number = 0 then exit function err.clear end if elseif primary.execs.exists(target) then getid = target exit function end if getid = null end function public function gethost(target) on error resume next if hosts.exists(target) then set gethost = hosts(target) if err.number = 0 then exit function err.clear end if set gethost = nothing end function public sub free(target) select case outline(target) case "multiprocess" on error resume next gethost(target).release = true err.clear case "Dictionary" dim elt for each elt in gethost(target) free(elt) next end select end sub public function joint(target, state, timeout) dim reftime reftime = timer select case outline(target) case "multiprocess", "Nothing" do while getstate(target) < state if timeisout(timeout, reftime) then joint = false exit function end if wscript.sleep 10 loop case "Dictionary" dim elt for each elt in gethost(target) do while getstate(elt) < state if timeisout(timeout, reftime) then joint = false exit function end if wscript.sleep 10 loop next end select joint = true end function private function timeisout(timeout, reftime) if timeout > 0 then dim delta delta = timer - reftime if delta < 0 then delta = delta + 86400 if delta > timeout then timeisout = true end if else timeisout = false end if end function public sub interrupt(target, timeout) select case outline(target) case "multiprocess" on error resume next with gethost(target).parent .wscript.timeout = timeout .wscript.quit end with err.clear case "Dictionary" dim elt for each elt in gethost(target) interrupt elt, timeout next end select end sub public sub kickout(target) if primary.execs.exists(target) then if getstate(target) < 64 then on error resume next primary.execs(target).terminate err.clear end if else select case outline(target) case "multiprocess" kickout getid(target) case "Dictionary" dim elt for each elt in gethost(target) kickout(elt) next end select end if end sub public sub terminate(target) interrupt target, 1 if not joint(target, 64, 2) then kickout target end sub public sub push(name, value) container.putproperty name, value end sub public function pop(name) on error resume next if isobject(container.getproperty(name)) then set pop = container.getproperty(name) else pop = container.getproperty(name) end if end function private sub scenequit if isprimary then dim col, i, status col = execs.keys for i = ubound(col) to 0 step -1 interrupt col(i), 1 next wscript.sleep 2000 on error resume next for i = ubound(col) to 0 step -1 status = execs(col(i)).status if err.number = 0 and status = 0 then execs(col(i)).terminate err.clear next container.quit end if end sub private sub class_terminate() if state < 28 and isprimary then scenequit end sub end class
説æïŒ
ãã«ãããã»ã¹ã¯ã©ã¹ã®ã¡ãœããïŒ
ã¯ã©ã¹åãã¡ãœããåããšã€ãªã¢ã¹åãèµ·åããŸã
ãµãŒãã¹ã¢ã«ãŽãªãºã ãèµ·åããã¹ã¯ãªããã®å®è¡ã¯åžžã«ãã®åŒã³åºãããå§ãŸããŸãã
ã¯ã©ã¹åãã¡ãœããåããšã€ãªã¢ã¹å-æååã ãããã¯ãã¿ãŒã²ããã¯ã©ã¹classnameãšãæ°ããããã»ã¹ã§å®è¡ããããã®ã¯ã©ã¹methodnameã®ã¡ãœããã瀺ããŸããã¯ã©ã¹classnameã®ã€ã³ã¹ã¿ã³ã¹ã¯ãaliasnameïŒaliasnameã空ã®æååã®å Žåã¯classnameïŒãšããååã®å€æ°ã«é 眮ãããŸãã
ãã®ã¡ãœããã®åŒæ°ã¯ãã¡ã€ã³ã³ãŒãã®å®è¡ãéå§ããããã«æåã«èµ·åãããã¹ã¯ãªããã§ã®ã¿äœ¿çšãããŸãã
æ°ããåã¹ã¯ãªããã§ïŒ
- å€æ°ã¯ãå®è¡äžã®ã¹ã¯ãªããã®ã°ããŒãã«ã¹ããŒã¹ã§å®£èšãããŸãã
scene-æåã®ã¹ã¯ãªããã®Meãªããžã§ã¯ããžã®åç §ã
host-ãã®ã¹ã¯ãªããã®ãã«ãããã»ã¹ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã
process -classnameãšããååã®ã¿ãŒã²ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ããã®ååã¯ããã®ã¹ã¯ãªããã®ããã»ã¹ãäœæãããšãã«åã®ã¹ã¯ãªããã«ãã£ãŠç€ºããããã®ã§ãã
ç¥å ã¯ãåè¿°ã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§ãã - å€æ°ã¯ãã°ããŒãã«ã¹ããŒã¹ã·ãŒã³ããã³ä»¥åã®ã¹ã¯ãªããã§ã aliasnameãšããååã§å®£èšãããŸã-ãã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã«ãªã³ã¯ããŸãã
- ãã¹ãããããã£ãèšå®ãããŸãã
primary-æåã®ã¹ã¯ãªããã®ãã«ãããã»ã¹ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãžã®åç §ã
ç¥å -åã®ã¹ã¯ãªããã®ãã«ãããã»ã¹ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãžã®åç §ã
parent-ãã®ã¹ã¯ãªããã®Meãªããžã§ã¯ãã
process-ã°ããŒãã«ç©ºéã§ã®ããã»ã¹ãžã®åç §ã
err-ãã®ã¹ã¯ãªããã®errãªããžã§ã¯ããžã®åç §ã
names-ãã©ã€ããªã§äœæããããšã€ãªã¢ã¹åãæã€èŸæžãžã®ãªã³ã¯ã
execs-ãã©ã€ããªã§äœæãããå®è¡äžã®ããã»ã¹ã®wshexecãªããžã§ã¯ããå«ãèŸæžãžã®ãªã³ã¯ã
ãã¹ã -ãã©ã€ããªã«ãã£ãŠäœæãããå®è¡äžã®ããã»ã¹ã®ãã¹ããªããžã§ã¯ãã䜿çšããŠèŸæžã«ãªã³ã¯ããŸãã
id-ãã®ã¹ã¯ãªããã®ã·ãªã¢ã«çªå·-èŸæžã®ããŒã
aid-åã®ã¹ã¯ãªãããšåãã
isprimary -booleanããã®ã¹ã¯ãªãããäž»ã«å®è¡ããããã©ããã
èŠã€ãã£ãã倱ããããã¢ã¯ãã£ã -ãã©ã€ããªã®ã¿-äœæãå®äºãããã³ã¢ã¯ãã£ããªã¹ã¯ãªããããã»ã¹ã®ã«ãŠã³ã¿ãŒã
ã¯ã©ã¹åãã¡ãœããåããšã€ãªã¢ã¹å -ã¹ã¯ãªããã®ç®çãå«ãã
permit = False-Trueãå²ãåœãŠãåŸãã¿ãŒã²ããã¡ãœãããèµ·åãããŸãã
release = False-ã¿ãŒã²ããã¡ãœããã®å®äºæã«ãTrueãå²ãåœãŠãåŸã«ã¹ã¯ãªãããå®äºããŸãã
state = 4-ãã®ã¹ã¯ãªãããé 眮ãããŠããç¶æ ã - èŸæžå ã exec ã hostsã«èŠçŽ ãè¿œå ãããŸã ã
startproc ïŒã¯ã©ã¹åãã¡ãœããåããšã€ãªã¢ã¹åïŒ
ã¯ã©ã¹åãã¡ãœããåããšã€ãªã¢ã¹å-launchïŒïŒãåç §ããŠãã ããã
æ°ããã¹ã¯ãªããããã»ã¹ãäœæããç¶æ 12ïŒgetstateïŒïŒãåç §ïŒã®æºåãã§ãããŸã§åŸ æ©ããã¿ãŒã²ããã¡ãœãããèµ·åããŸãã æ°ããããã»ã¹ã§åæåãããã¿ãŒã²ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãžã®åç §ãè¿ããŸãã
createproc ïŒã¯ã©ã¹åãã¡ãœããåã ãšã€ãªã¢ã¹åïŒ
ã¯ã©ã¹åãã¡ãœããåããšã€ãªã¢ã¹å-launchïŒïŒãåç §ããŠãã ããã
åŸ æ©ããã«æ°ããã¹ã¯ãªããããã»ã¹ãäœæãããã®IDãè¿ããŸãã åããã»ã¹ã®æºåãæŽãã®ãåŸ ããã«ãã«ãŒãã§è€æ°ã®ããã»ã¹ãéåæçã«äœæããããã«äœ¿çšããŸãã ãã®ãããªã¢ããªã±ãŒã·ã§ã³ã§startprocïŒïŒã䜿çšãããããèããé«éã§ãã
éå§ ïŒã¿ãŒã²ããïŒ
target-äœæãããã¹ã¯ãªããã®ã°ã«ãŒãã®çªå·ãã¹ã¯ãªããIDããŸãã¯æååããšã€ãªã¢ã¹åã
createprocïŒïŒã䜿çšããŠäœæãããã¹ã¯ãªãããç¶æ 12ã«éãããŸã§åŸ æ©ããã¿ãŒã²ããã¡ãœããã®å®è¡ãèš±å¯ããŸãã ã°ã«ãŒãã«åããšã€ãªã¢ã¹åãæã€ã¹ã¯ãªããã䜿çšããããšãã§ããŸãã 1ã€ã®ã¹ã¯ãªããã§ã¯ãæ°ããããã»ã¹ã§åæåãããã¿ãŒã²ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãžã®ãªã³ã¯ãè¿ããŸããã¹ã¯ãªããã®ã°ã«ãŒãã§ã¯ãaliasnameããŒã¿ãæã€ãã¹ãŠã®ãã¹ããå«ââããµãèŸæžãžã®ãªã³ã¯ãè¿ããŸãã
gethost ïŒã¿ãŒã²ããïŒ
target-çªå·ãã¹ã¯ãªããIDãŸãã¯æååãäœæãããã¹ã¯ãªããã®ã°ã«ãŒãã®ãšã€ãªã¢ã¹åããŸãã¯ã¹ã¯ãªããããã»ã¹ãªããžã§ã¯ãã
å¿ èŠãªã¹ã¯ãªããã®ãã«ãããã»ã¹ã¯ã©ã¹ã®ãã¹ãã€ã³ã¹ã¿ã³ã¹ãžã®ã¢ã¯ã»ã¹ãæäŸããŸãã 1ã€ã®ã¹ã¯ãªããã«ã€ããŠã¯ãã¹ããžã®ãªã³ã¯ãè¿ããã¹ã¯ãªããã®ã°ã«ãŒãã«ã€ããŠã¯ãidãèŠã€ãããªããã¹ã¯ãªãããå®äºããå Žåããšã€ãªã¢ã¹åããŒã¿ãæã€ãã¹ãŠã®ãã¹ããå«ââããµãèŸæžãžã®ãªã³ã¯ãè¿ããŸã-äœããããŸããã
getid ïŒã¿ãŒã²ããïŒ
target-ã¹ã¯ãªããã®çªå·ãIDããŸãã¯ã¹ã¯ãªããã®ããã»ã¹ãªããžã§ã¯ãã
ããã»ã¹ãªããžã§ã¯ãã«ãã£ãŠèå¥ãããã¹ã¯ãªããã®IDãè¿ããŸãã æ¢åã®ã¹ã¯ãªããã®ã¿ã
getstate ïŒã¿ãŒã²ããïŒ
ã¿ãŒã²ãã-getidïŒïŒãåç §ã
ã¹ã¯ãªããã®ç¶æ ã決å®ããŸãã æ°å€ãå®è¡ã¹ããããè¿ããŸãã
0ãèŠã€ãããŸããïŒãã¹ããèŠã€ãããŸããïŒã
1ã€ã®ããã»ã¹ãäœæãããŸããïŒæ°ããããã»ã¹execïŒã
4ãã¹ããåæåãããŸãã
8ã¿ãŒã²ããã¯ã©ã¹ã®åæåïŒããã»ã¹ã®åæåïŒã
12ã¿ãŒã²ããã¯ã©ã¹ãåæåãããã€ãã³ããåŠçãããŸããïŒããã»ã¹ã®åæåãåŠçãããŸããïŒã
16åã®ã¿ãŒã²ããã¡ãœããã®èµ·åïŒããã»ã¹ã¡ãœããã®èµ·åïŒã
20ã¿ãŒã²ããã¡ãœãããå®äºïŒããã»ã¹ãå®äºïŒã
24åã®ã¿ãŒã²ããã¡ãœãããå®äºããã€ãã³ããåŠçãããŸããïŒåŠçãå®äºããŸããïŒ
28åã®ã¹ã¯ãªããããªãªãŒã¹ãããŸãã
64ã¹ã¯ãªãããå®äºããŸããïŒçµäºããŸããïŒã
isresponsive ïŒã¿ãŒã²ããïŒ
ã¿ãŒã²ãã-getidïŒïŒãåç §ã
ãã¹ãã¹ã¯ãªãããªããžã§ã¯ãã®å¯çšæ§ã決å®ããŸãïŒç¶æ 4ã28ïŒã ããŒã«å€ãè¿ããŸãã
assignhandler handlernameãvarsqty
handlername-æååãã€ãã³ãåãvarsqty-æž¡ãããåŒæ°ã®æ°ã
ã€ãã³ãåhandlernameã䜿çšããŠã°ããŒãã«ã¹ããŒã¹ã«ãµãã€ãã³ããã³ãã©ãäœæããäœæãããããã»ã¹ãªããžã§ã¯ãå ã®åãååã®ã¡ãœããã«é¢é£ä»ããŸãã ã€ãã³ããçºçãããšããã³ãã©ãŒã¯åŒã³åºããããã»ã¹ã«ãªãã€ã¬ã¯ãããŸãã ãã³ãã©ãŒåïŒïŒã
executecommandã³ãã³ã
commandã¯æ瀺ãå«ãæååã§ãã
ã€ã³ã¿ãŒããªã¿ãŒãåŒã³åºããŠãã°ããŒãã«ã¹ã¯ãªããã¹ããŒã¹ã§ã¹ããŒãã¡ã³ããå®è¡ããŸãã
newvar varname
varnameã¯ãå€æ°ã®ååãå«ãæååã§ãã
ã°ããŒãã«ã¹ã¯ãªããã¹ããŒã¹ã§æ°ããå€æ°ã宣èšããŸãã
ç¡æã®ã¿ãŒã²ãã
ã¿ãŒã²ãã-gethostïŒïŒãåç §ããŠãã ããã
ã¿ãŒã²ããã¡ãœããã®å®è¡åŸã«ã¹ã¯ãªãããçµäºã§ããŸãã åäžã®ã¹ã¯ãªãããŸãã¯ã°ã«ãŒãã§åäœããŸãã
ãžã§ã€ã³ã ïŒã¿ãŒã²ãããç¶æ ãã¿ã€ã ã¢ãŠãïŒ
target-gethostïŒïŒãåç §ãstate-getstateïŒïŒãåç §ãtimeout-ããªç§åäœã®ç§åäœã®æ°å€ã
ç¶æ ã¹ã¯ãªãããå°çãããŸã§åŸ æ©ããŸããã¹ã¯ãªããã®ã°ã«ãŒãã§ã¯ããããããç¶æ ã«å°éãããŸã§åŸ æ©ããŸãã åŸ æ©ã¯ã¿ã€ã ã¢ãŠãã«ãã£ãŠå¶éãããŸããã¿ã€ã ã¢ãŠã= 0ã¯ç¡å¶éã®åŸ æ©ãæå³ããŸãã ããŒã«å€ãTruth-åŸ æ©ã¯çµäºãFalse-ã¿ã€ã ã¢ãŠããè¿ããŸãã ã¹ã¯ãªãããåæããããã«èšèšãããŠããŸãã ããšãã°ãããã»ã¹-8ãªããžã§ã¯ããäœæããããŸã§åŸ ã€å¿ èŠãããå Žåãã¹ã¯ãªããã¯å®äºããŸã-64ã
å²ã蟌ã¿ã¿ãŒã²ãããã¿ã€ã ã¢ãŠã
target-gethostïŒïŒãåç §ãtimeout-ç§åäœã®wscript.timeoutã®å€ã
class_terminateã¡ãœããã®å®è£ ã«ãããã¹ã¯ãªãããéåžžã®å®äºã«å€æããŸãã ã¹ã¯ãªããã§ãã€ã¢ãã°ããã¯ã¹ãéãããå Žåãã¿ã€ã ã¢ãŠãã®äžæåæ¢åŸã«ã®ã¿å®äºããŸãã class_terminateã¡ãœããã§ãã€ã¢ãã°ããã¯ã¹ãå衚瀺ãããšãå®äºãåæ¢ããŸãã
ããã¯ã¢ãŠãã¿ãŒã²ãã
ã¿ãŒã²ãã-gethostïŒïŒãåç §ããŠãã ããã
wshexec.terminateã䜿çšããŠãOSã¬ãã«ã§ã¹ã¯ãªããããã»ã¹ãçµäºããŸãã é·ãå®è¡ãå¯èœã§ããã¹ã¯ãªããããšã«æ倧2ç§ã§ãã åäžã®ã¹ã¯ãªãããŸãã¯ã°ã«ãŒãã§åäœããŸãã
ã¿ãŒã²ãããçµäº
ã¿ãŒã²ãã-gethostïŒïŒãåç §ããŠãã ããã
ã¹ã¯ãªãããå®äºããæåã«å²ã蟌ã¿ã䜿çšããŠãããå¿ èŠã«å¿ããŠããã¯ã¢ãŠãããŸãã
ããã·ã¥åãå€
name-æååãããããã£åãvalue-ä»»æã®å€ã
nameãšããååã®GlobalContainerããããã£ã«valueã®å 容ãå ¥ããŸãã
ããã ïŒååïŒ
name-æååãããããã£åã
GlobalContainerããnameãšããååã®ããããã£ã®å 容ãè¿ããŸãã
ãã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¯ã©ã¹ã«ãã¿ãŒã²ããã¯ã©ã¹ã®åæåããã³å®è¡äžã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¡ãœããã®å®è¡ã®ã€ãã³ãã®ãã³ãã©ãŒãšããŠé 眮ã§ããã¡ãœããïŒ
<ãšã€ãªã¢ã¹å> _ oninitialized ïŒãœãŒã¹ïŒ
source-ã¡ãœããã«æž¡ãããã¡ãœãããåŒã³åºããã¹ã¯ãªããã®ãã¹ããªããžã§ã¯ã;ãã®ãšã€ãªã¢ã¹åã¯ã¡ãœããåã«å«ãŸããŠããŸãã ãã®ã¡ãœããã¯ãå®è¡äžã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¯ã©ã¹ã®åæååŸã«åŒã³åºãããŸãïŒç¶æ = 8ïŒã
<ãšã€ãªã¢ã¹å> _ oncompleted ïŒãœãŒã¹ïŒ
source-ã¡ãœããã«æž¡ãããã¡ãœãããåŒã³åºããã¹ã¯ãªããã®ãã¹ããªããžã§ã¯ã;ãã®ãšã€ãªã¢ã¹åã¯ã¡ãœããåã«å«ãŸããŠããŸãã ã¡ãœããã¯ãå®è¡äžã®ã¹ã¯ãªããã®ã¿ãŒã²ããã¡ãœãããå®è¡ããåŸã«åŒã³åºãããŸãïŒç¶æ = 20ïŒã
äŸïŒ
mprocliteããã³mprocã®å Žåãæœè±¡ã¿ã¹ã¯ã®äŸã瀺ãããŸããæååã®æåããæåããšã«åå¥ã®ããã»ã¹ãäœæãããã«ãŒãå ã®åããã»ã¹ããããã¡ãŒã«ç¬èªã®æåãå ¥ããŸãã WScriptã®å Žåãã³ã³ãœãŒã«ã¯IEãŠã£ã³ããŠã«ãã£ãŠã·ãã¥ã¬ãŒããããŸãã éäžã§ãéå§ããã³åæ¢ãããOSããã»ã¹ã衚瀺ãããŸãïŒäŸã§ã¯WMIã䜿çšãããŠããŸãããã¡ã«ããºã ãæ©èœããå¿ èŠã¯ãããŸããïŒã
ãããã°äžãç§ã¯ããã€ãã®èŠ³å¯ãšã³ã¡ã³ããèç©ããŸãããéèŠãããã°å ±æããŸããäºå®ãããããèªã¿ããã圢åŒã«ããã®ã«æéãããããšããããšã§ãã 建èšçãªæ¹å€ã¯å€§æè¿ã§ãã