View Full Version : Get the calling program of an avisynth script
WarpEnterprises
28th December 2012, 18:08
Hi!
Is it possible to get the name of the program which called the
current script?
My sample usage would be:
virtualdub calls script -> don't use e.g. deshaker filter
else -> use deshaker
Of course, any hint how to achieve the same is welcome, too!
StainlessS
28th December 2012, 20:04
This gets a number of hits in google:- "get parent process name"
you'de need a plugin of course.
WarpEnterprises
28th December 2012, 20:26
OK - I forget to add "with already existing tools" :)
StainlessS
29th December 2012, 13:05
OK - I forget to add "with already existing tools" :)
Not already existing, but having a go at your requirement.
So far, got a plug that outputs list of current processes, names,
PID, parent PID (to Debugview).
Found that what you want is actually the name of the current
process rather than parent (did not know if Avisynth dll had it's own process ID or not, I am not a Win programmer).
I'll have it return a string (process name) if successful and maybe an int or bool to flag failure.
When it's done, (not too long I hope) perhaps you would be good enough to give a report on how it fares and on what system.
StainlessS
29th December 2012, 14:20
Last bit was easier than anticipated, here it is:
http://www.mediafire.com/?3ri1n01hh3wacmy
GetProcessName(bool "Parent"=false,bool "Debug"=false)
Args:-
Parent, if false gives name of current process (eg mplayer2.exe or VirtualDubMod.exe).
if true gives name of parent to current process (eg Explorer.exe or AVSEdit.exe).
Debug, if true outputs stuff to DebugView (need debugview, see google)
Returns:-
Type int
-1 = Cant create process snapshot. (CreateToolhelp32Snapshot)
-2 = Cant walk Process List. (Process32First)
-3 = Cant find my own PID in process list (???).
-4 = Cant find Parent PID in process list (No longer executing).
Type String = ExeName as shown in Taskmanager.
Test Script GetProcessName.avs
# -----------------------
Me = GetProcessName(parent=false,debug=true)
RT_Debug("MY NAME IS ",String(Me))
Mum= GetProcessName(parent=true ,debug=true)
RT_Debug("MUMS NAME IS ",String(Mum))
return colorbars() # Avoid ThrowError
# -----------------------
Gives this output in DebugView
00000004 1.88071465 [3364] GetProcessName: ExeFile = VirtualDubMod.exe
00000005 1.88075864 [3364] GetProcessName: ProcessID = 0x00000D24
00000006 1.88080537 [3364] GetProcessName: Threads = 3
00000007 1.88085139 [3364] GetProcessName: ParentProc = 0x00000140
00000008 1.88463914 [3364] RT_Debug: MY NAME IS VirtualDubMod.exe
00000009 1.88716698 [3364] GetProcessName: ExeFile = VirtualDubMod.exe
00000010 1.88721681 [3364] GetProcessName: ProcessID = 0x00000D24
00000011 1.88726258 [3364] GetProcessName: Threads = 3
00000012 1.88730943 [3364] GetProcessName: ParentProc = 0x00000140
00000013 1.88757229 [3364] GetProcessName: ExeFile = explorer.exe
00000014 1.88761711 [3364] GetProcessName: ProcessID = 0x00000140
00000015 1.88766301 [3364] GetProcessName: Threads = 13
00000016 1.88770759 [3364] GetProcessName: ParentProc = 0x000007DC
00000017 1.88853240 [3364] RT_Debug: MUMS NAME IS explorer.exe
EDITED
Tested only on XP32 (XP and above, NOT W2K)
If a Win progger could check out the source for obvious errors, that would be nice. :) Thank you.
EDIT: Tested on XP32, Vista32, W7-32 & also works on W2K :)
EDIT: Detects AVSPmod fine.
jmartinr
29th December 2012, 14:46
See here: http://forum.doom9.org/showthread.php?p=1260197#post1260197
And download the plugin here: http://www.roelofs-coaching.nl/blobs/downloads/ProgramName.zip
StainlessS
29th December 2012, 16:40
Post #5 updated with two new args Parent and Debug. (will also be adding to RT_Stats).
WarpEnterprises
29th December 2012, 19:34
@StainlessS: thanks very much - tested on XP and W2K, works as expected!
StainlessS
29th December 2012, 19:44
Verify, W2K work OK ? (not supposed to).
WarpEnterprises
29th December 2012, 22:06
Well, at least it did not crash and returned the correct task name (loaded from vdub).
Which function did you suspect to be incompatible?
StainlessS
30th December 2012, 04:42
GetCurrentProcessId : Minimum supported client Windows XP [desktop apps only]
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms683180%28v=vs.85%29.aspx
CreateToolhelp32Snapshot : Minimum supported client Windows XP [desktop apps only]
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms682489%28v=vs.85%29.aspx
Process32First : Minimum supported client Windows XP [desktop apps only]
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms684834%28v=vs.85%29.aspx
Process32Next : Minimum supported client Windows XP [desktop apps only]
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms684836%28v=vs.85%29.aspx
Might be a case of "We no longer support W2K, and so now neither do you !"
Thanks for the verification. :)
EDIT: Tested on XP32, Vista32, W7-32 & also works on W2K :)
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.