Sorry for the late answer.
Yes, you can find out which parent process started your program. Provided the program that starts your program is still running:
Code:
;YourProgram.exe
EnableExplicit
Procedure GetParentPID()
Protected hSnapshot
Protected PROCESSENTRY32.PROCESSENTRY32
Protected bProcess
hSnapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, #Null)
If hSnapshot
PROCESSENTRY32\dwsize = SizeOf(PROCESSENTRY32)
bProcess = Process32First_(hSnapshot, @PROCESSENTRY32)
If bProcess
Repeat
If PeekS(@PROCESSENTRY32\szExeFile, 260) = GetFilePart(ProgramFilename())
CloseHandle_(hSnapshot)
ProcedureReturn PROCESSENTRY32\th32ParentProcessID
EndIf
bProcess = Process32Next_(hSnapshot, @PROCESSENTRY32)
Until Not bProcess
EndIf
CloseHandle_(hSnapshot)
EndIf
EndProcedure
Procedure.s GetProcessPath(PID)
Protected hSnapshot
Protected PROCESSENTRY32.PROCESSENTRY32
Protected bProcess
hSnapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, #Null)
If hSnapshot
PROCESSENTRY32\dwsize = SizeOf(PROCESSENTRY32)
bProcess = Process32First_(hSnapshot, @PROCESSENTRY32)
If bProcess
Repeat
If PROCESSENTRY32\th32ProcessID = PID
CloseHandle_(hSnapshot)
ProcedureReturn PeekS(@PROCESSENTRY32\szExeFile)
EndIf
bProcess = Process32Next_(hSnapshot, @PROCESSENTRY32)
Until Not bProcess
EndIf
CloseHandle_(hSnapshot)
EndIf
EndProcedure
MessageRequester("Info", "Parent Process: " + GetProcessPath(GetParentPID()), 0)
If you start your program directly, then "explorer.exe". If you start your program with a separate program, then "AnotherProgram.exe":
Code:
;AnotherProgram.exe
EnableExplicit
If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
RunProgram("YourProgram.exe")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf