Detect 16bits process

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
theelf
Posts: 12
Joined: 24 Nov 2015, 19:16

Detect 16bits process

20 Jun 2021, 06:41

Hi, there is some way to detect 16bits process? for example if i open old win3x tetris, in task manager i get

ntvdm.exe
wowexec.exe
tetris.exe


if i use If ProcessExist("ntvdm.exe") works well, but sadly i realize after close a 16bits app ntvdm is still on background

If i try If ProcessExist("tetris.exe") is not working, never detect


I tried with IfWinExist, tetris works, but i preffer process, because i use a 16bits application that change the window name often (medical stuff)



My OS is XP Sp3


thanks a lot for any help
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Detect 16bits process

21 Jun 2021, 13:49

there is some way to detect 16bits process?
VDMEnumProcessWOW()
These VDMs contain the WowExec.exe task. DOS VDMs are not enumerated. To enumerate DOS VDMs, you need to use another method. First, you could use VDMEnumProcessWOW() to make a list of all Win16 VDMs, and then enumerate all instances of NTVDM.exe using some other scheme (such as PSAPI). Any NTVDM.exe from the full enumeration that was not in the Win16 list is a DOS VDM.
http://web.archive.org/web/20110317233038/http://support.microsoft.com/kb/182559
http://web.archive.org/web/20210621185123/https://stackoverflow.com/questions/4121383/reliably-detect-16-bit-process

Code: Select all

if !VdmDbgDLL := DllCall("LoadLibrary", "Str", "VdmDbg.dll", "Ptr") ; might have to give it a full path, idk where its located by default
{
	MsgBox failed to load VdmDbg.dll`nErrorLevel: %ErrorLevel%`nA_LastError: %A_LastError%
	ExitApp
}

ProcessVDMsProc := RegisterCallback("ProcessVDMs")
DllCall("VdmDbg\VDMEnumProcessWOW", "Ptr", ProcessVDMsProc, "Ptr", 0)

ProcessVDMs(dwProcessId, dwAttrib, t) {
	MsgBox % "Process ID: " dwProcessId

	static ProcessTasksProc := RegisterCallback("ProcessTasks")

	; Use process ID of VDM to enumerate through its tasks
	DllCall("VdmDbg\VDMEnumTaskWOWEx", "UInt", dwProcessId, "Ptr", ProcessTasksProc, "Ptr", 0)

	return false ; Keep enumerating 
}

ProcessTasks(dwThreadId, hMod16, hTask16, pszModName, pszFileName, lParam) {
	; Print task's information
	str := "Thread ID: " dwThreadId
	str .= "`nModule handle: " hMod16
	str .= "`nTask handle: " hTask16
	str .= "`nModule Name: " StrGet(pszModName) ; may be wrong
	str .= "`nFile Name: " StrGet(pszFileName) ; may be wrong

	MsgBox % str

	return false ; Keep enumerating 
}
thats the sample rewritten. i dont know if it will work. i cant test it(nor would i, if i could). it also doesnt handle the caveat mentioned in the remarks
I tried with IfWinExist, tetris works, but i preffer process, because i use a 16bits application that change the window name often (medical stuff)
why not use SetTitleMatchMode's RegEx option then instead? this would allow u to match changing titles(provided they follow at least some semblance of a pattern)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 302 guests