J
Jake Thompson
Anybody know what I am doing wrong when I try and get the handle of
the process?
Private Declare Function OpenProcess Lib "kernel32" (ByVal
dwDesiredAccess As Long, ByVal blnheritHandle As Boolean, ByVal
dwAppProcessId As IntPtr) As IntPtr
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Const SW_MAXIMIZE = 3
Const SW_RESTORE = 9
Const SHOWNORMAL = 1
Private Declare Function ShowWindow Lib "user32" (ByVal handle As
IntPtr, ByVal nCmdShow As Integer) As Integer
Private Declare Function GetLastError Lib "kernel32" () As Long
If LBSessions.SelectedIndex > -1 Then
Dim selection As String = LBSessions.SelectedItem.ToString
Dim theid As String = selection.Substring(40, 4)
Dim pid As String
'the usage in the sub
Dim theProcesses() As Process =
Process.GetProcessesByName("Foo")
For Each p As Process In theProcesses
pid = p.Id
MsgBox(theid)
MsgBox(pid)
If theid = pid Then <---theid and the pid match up so
it's finding the process I want
MsgBox("in here")
'hWnd = p.Handle <---Tried this it returns a
number but ShowWindow does not bring up the window
'hWnd = OpenProcess(PROCESS_ALL_ACCESS, False,
pid) <--- tried this hWnd came back 0
hWnd = OpenProcess(PROCESS_ALL_ACCESS, False,
(Convert.ToInt32(pid))) <--- tried this hWnd came back 0
'hWnd =
Diagnostics.Process.GetProcessesByName("Foo")
(0).MainWindowHandle.ToInt32 <--- tried this hWnd came back 0
Dim theerror As Long = GetLastError()
MsgBox(theerror) <----- The last error for the
last three hwnd calls is 87 Invalid Parameter
ShowWindow(hWnd, SW_RESTORE)
End If
Next
End If
What I want to do is get a handle to the process so that I can show
the application that it's related to on the screen
Am I on the right track - completely wrong, or something else.
Help?
Thanks
Jake
the process?
Private Declare Function OpenProcess Lib "kernel32" (ByVal
dwDesiredAccess As Long, ByVal blnheritHandle As Boolean, ByVal
dwAppProcessId As IntPtr) As IntPtr
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Const SW_MAXIMIZE = 3
Const SW_RESTORE = 9
Const SHOWNORMAL = 1
Private Declare Function ShowWindow Lib "user32" (ByVal handle As
IntPtr, ByVal nCmdShow As Integer) As Integer
Private Declare Function GetLastError Lib "kernel32" () As Long
If LBSessions.SelectedIndex > -1 Then
Dim selection As String = LBSessions.SelectedItem.ToString
Dim theid As String = selection.Substring(40, 4)
Dim pid As String
'the usage in the sub
Dim theProcesses() As Process =
Process.GetProcessesByName("Foo")
For Each p As Process In theProcesses
pid = p.Id
MsgBox(theid)
MsgBox(pid)
If theid = pid Then <---theid and the pid match up so
it's finding the process I want
MsgBox("in here")
'hWnd = p.Handle <---Tried this it returns a
number but ShowWindow does not bring up the window
'hWnd = OpenProcess(PROCESS_ALL_ACCESS, False,
pid) <--- tried this hWnd came back 0
hWnd = OpenProcess(PROCESS_ALL_ACCESS, False,
(Convert.ToInt32(pid))) <--- tried this hWnd came back 0
'hWnd =
Diagnostics.Process.GetProcessesByName("Foo")
(0).MainWindowHandle.ToInt32 <--- tried this hWnd came back 0
Dim theerror As Long = GetLastError()
MsgBox(theerror) <----- The last error for the
last three hwnd calls is 87 Invalid Parameter
ShowWindow(hWnd, SW_RESTORE)
End If
Next
End If
What I want to do is get a handle to the process so that I can show
the application that it's related to on the screen
Am I on the right track - completely wrong, or something else.
Help?
Thanks
Jake