Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How do i get the process ID in VB

I was looking under my.application but couldn't find how to get the process id or shoud i say a simpler way then i did in VB6 and iwas curious to know if it was possible
[174 byte] By [christianbg] at [2007-11-11 10:21:33]
# 1 Re: How do i get the process ID in VB
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer

this is the was i declared it in VB 6 and VB.net but in .NET i am getting and index out range error when i try to attach the value in the variable to a string.

"GetWindowThreadProcessId" returns a value to a varaible I have cast it with cstr() and forced it with .tostring still it won't work the same way.

I am not sure how to proceed. thank you for any help
christianbg at 2007-11-11 20:48:11 >
# 2 Re: How do i get the process ID in VB
Try:

Dim currentProcess As Process = Process.GetCurrentProcess()
MessageBox.Show(currentProcess.Id.ToString)

MS Help (ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref6/html/M_System_Diagnostics_Process_GetCurrentProcess.htm)
joewmaki at 2007-11-11 20:49:06 >