'获取父进程ID,PID是要查的进程ID，默认为自己软件的进程ID
#Include  Once "win\tlhelp32.bi"
Function GetParentPID(PID as DWord = GetCurrentProcessId) as DWord
   Dim p as WINBOOL, Proc as PROCESSENTRY32, hSnap as HANDLE
   If pid = 0 Then pid = GetCurrentProcessId
   hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
   If hSnap = 0 Then Exit Function
   Proc.dwSize = SizeOf(PROCESSENTRY32)
   p = Process32First(hSnap, @Proc)
   While p
      If Proc.th32ProcessID = PID Then
         Function = Proc.th32ParentProcessID
         CloseHandle hSnap : Exit Function
      End If
      p = Process32Next(hSnap, @Proc)
   Wend
   CloseHandle hSnap
End Function