How can i get the PID of the Process which started me (my exe) - I'm seeking for the PID from the cmd.exe process (my program is started from an batch-job).
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
This class is used for managing processes and their children, including a method for killing all of a processes shelled children.
I am sure that you can get that snipped and adapt it for your needs. It generates an array of UDTS which holds the relationship of a processId, and it's parentprocessid. All you'd need to do is iterate down the list looking for your processid, and then read of the parentid
"As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein
if there is more than one, then it may or may not pick the one that you want. If the Console Window you want has a different Window Title from the other consoles, then you could include that in the FindWindow() so it gets the one that you want, for instance:
hwnd = FindWindow("ConsoleWindowClass", "Enter Window Title Here")