Page 1 of 2 12>
Topic Options
#129927 - 2004-11-19 06:11 PM Challenge for a slow day ...
Shawn Administrator Offline
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
#129928 - 2004-11-19 07:24 PM Re: Challenge for a slow day ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doesn't START have such a switch?
_________________________
!

download KiXnet

Top
#129929 - 2004-11-19 08:04 PM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
sooo ... show me the money !
Top
#129930 - 2004-11-19 09:01 PM Re: Challenge for a slow day ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
too busy, you know
_________________________
!

download KiXnet

Top
#129931 - 2004-11-19 09:23 PM Re: Challenge for a slow day ...
eriqjaffe Offline
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
#129932 - 2004-11-19 10:39 PM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hehee, good one - clever! What i was hoping to accomplish was that if the "user" canceled the script (however), that the child process would automatically terminate as well ... ja
Top
#129933 - 2004-11-19 10:41 PM Re: Challenge for a slow day ...
Howard Bullock Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#129934 - 2004-11-19 10:48 PM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, was hoping not to go to that extreme ...
Top
#129935 - 2004-11-20 12:31 AM Re: Challenge for a slow day ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
cool!
so, hoby only one with acceptable answer.
really nice one.
I have one other already.
it's long but a nicey...
just need to get it written.
_________________________
!

download KiXnet

Top
#129936 - 2004-11-20 01:06 AM Re: Challenge for a slow day ...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Shawn, you old mod', forgot the Scripts Forum rules about including a script in the initial post? ;-)
_________________________
There are two types of vessels, submarines and targets.

Top
#129937 - 2004-11-20 01:10 AM Re: Challenge for a slow day ...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shawn, the old mod', got moderated. LOL
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129938 - 2004-11-20 01:12 AM Re: Challenge for a slow day ...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Happens to the best of us ;-)
_________________________
There are two types of vessels, submarines and targets.

Top
#129939 - 2004-11-20 01:14 AM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I posted here very much on purpose ...
Top
#129940 - 2004-11-20 01:14 AM Re: Challenge for a slow day ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
this moved?
can't see any notes...
_________________________
!

download KiXnet

Top
#129941 - 2004-11-20 01:19 AM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja, general discussion is a much better place to be talking about a kixtart script.
Top
#129942 - 2004-11-20 01:30 AM Re: Challenge for a slow day ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
maybe...
anyway, back to the challenge...
a direct child-parent stuff is little "eh":
Quote:

The Win32 specification states that no relationship exists between a parent process and any of its child processes once a child process has been created. Many other operating systems support a parent/child relationship policy, so if you kill a process, the system automatically kills all of the process's descendant processes.




http://www.microsoft.com/msj/0698/win320698.aspx
_________________________
!

download KiXnet

Top
#129943 - 2004-11-20 01:39 AM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Thank you Jooel ... that is the magic information i was looking for. There is no parent-child relationship, so no straight-forward way of doing this.
Top
#129944 - 2004-11-20 01:46 AM Re: Challenge for a slow day ...
Bryce Offline
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
#129945 - 2004-11-20 01:56 AM Re: Challenge for a slow day ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja bryce, that looks so much like mine.
different approach but finally the logic behind is same.

sadly shawn said it's too complex.
he wants 1 liner [censored].
_________________________
!

download KiXnet

Top
#129946 - 2004-11-20 02:05 AM Re: Challenge for a slow day ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
What you saying Bryce ? This script is like that ugly girl at the office (that everyone has) ? The one that for some reason we can't stop fantasizing about ? ;0)
Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.076 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org