#129927 - 2004-11-19 06:11 PM
Challenge for a slow day ...
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Since it's a slow day, thought I would pump the korg brain-trust with a challenge ...
Can anybody think of a way, using RUN or SHELL or maybe even COM (wsh what have you) to be able to do the following ...
At the beginning of the script, start an instance of an exe (say - notepad.exe for example), have notepad running "in the background", yet get control returned back to your script (because the script needs to do stuff while notepad is displayed), then (and here's the trick) ... be able to AUTOMATICALLY close-down notepad when the script terminates (without explicitly killing the notepad process) ...
Say for example, the assumption would be that notepad would be some kind of "child" process that would automatically terminate when the parent process (kix32) terminated.
If this is not possible (not sure if it is), then kill the notepad process somehow, without alot of muss and fuss. But ideally, if this child process could be killed by default, that would be the best.
Thoughts anyone ?
For example... the script would start like this. The following is the script ... see the script below ... the script is coming next, here it is ...
Code:
Break On
; Your code here
Exit 0
-Shawn
|
Top
|
|
|
|
#129931 - 2004-11-19 09:23 PM
Re: Challenge for a slow day ...
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Well, it may not be the most elegant way to do it, but...
Code:
Break on
Run "%comspec% /c start /min notepad.exe"
Sleep(5) ;or whatever code you'd like
If SetFocus ("Untitled - Notepad") = 0 $rc = SendKeys("~{F4}Y") EndIf
|
Top
|
|
|
|
#129933 - 2004-11-19 10:41 PM
Re: Challenge for a slow day ...
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If you have "Break OFF" then when the user canceled the script the user session would close (logoff) closing notepad.
Edited by Howard Bullock (2004-11-19 10:41 PM)
|
Top
|
|
|
|
#129944 - 2004-11-20 01:46 AM
Re: Challenge for a slow day ...
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
its rude.. crude.... and ugly as all sin to look at.... but....
Code:
break on $ = setoption("novarsinstrings","on") if $guarddog guarddog($guarddog) exit endif
$Current = enumprocess("notepad.exe") run "notepad.exe" $new = enumprocess("notepad.exe") $notepad = substr($new,1,instr($new,$current)-2)
run '%comspec% /c start /min kix32 "' + @scriptdir + "\" + @scriptname + '" $guarddog='+@pid+","+$notepad
? "press any key to end script and close NOTEPAD.exe" get $x
function guarddog($data) while enumprocess(split($data,",")[0]) sleep 0.5 loop enumprocess(split($data,",")[1],1) endfunction
FUNCTION EnumProcess($exe, optional $terminate, optional $Computer) Dim $winmgmts, $ExecQuery, $Process, $id if not $computer $computer=@wksta endif $winmgmts="winmgmts:{impersonationLevel=impersonate}!//" + $COMPUTER select case val($exe)>0 $ExecQuery="select * from Win32_Process where ProcessId='" + $exe + "'" $GetObject=GetObject($winmgmts).ExecQuery($ExecQuery) For each $Process in $GetObject if $terminate $=$Process.Terminate endif $EnumProcess = $Process.name next $GetObject='' case vartype($exe)=8 $ExecQuery="select * from Win32_Process where Name='" + $exe + "'" $GetObject=GetObject($winmgmts).ExecQuery($ExecQuery) For each $Process in $GetObject if $terminate $=$Process.Terminate endif $id=$Process.ProcessId $EnumProcess = "" + $Id + "|" + $EnumProcess Next $EnumProcess=left($EnumProcess,len($EnumProcess)-1) $GetObject='' case 1 exit 1 endselect ENDFUNCTION
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 255 anonymous users online.
|
|
|