|
-
Jul 21st, 2004, 12:09 PM
#1
Thread Starter
Member
[Resolved] n00b to VB.NET need help.
Ok, I am running into an error I dont quite understand and looking at the MSDN files is a tad bit confusing. The following is the code from my module file. BUT it now does not work under visual basic.net is someone can help me out that would be awsome!
VB Code:
Public oIE As Object
Public glPid As Integer
Public glHandle As Integer
Public colHandle As New Collection
Public glHwnd As Integer
Public Const SMTO_BLOCK As Short = &H1s
Public Const SMTO_ABORTIFHUNG As Short = &H2s
Public Const WM_NULL As Short = &H0s
Public Const WM_CLOSE As Short = &H10s
Public Const WM_DESTROY As Short = &H2s
Public Const PROCESS_ALL_ACCESS As Integer = &H1F0FFF
'UPGRADE_ISSUE: Declaring a parameter 'As String' is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1016"'
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As String) As Integer
Declare Function GetParent Lib "user32" (ByVal hwnd As Integer) As Integer
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
Declare Sub ReleaseCapture Lib "user32" ()
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessID As Integer) As Integer
Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA"(ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer, ByVal fuFlags As Integer, ByVal uTimeout As Integer, ByRef pdwResult As Integer) As Integer
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Integer, ByVal uExitCode As Integer) As Integer
Public Function fEnumWindowsCallBack(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
Dim lParent As Integer
Dim lThreadId As Integer
Dim lProcessId As Integer
fEnumWindowsCallBack = 1
lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)
If glPid = lProcessId Then
glHwnd = hwnd
fEnumWindowsCallBack = 0
lParent = GetParent(hwnd)
If lParent = 0 Then
colHandle.Add(hwnd)
End If
Else
End If
End Function
Public Function fEnumWindows() As Boolean
Dim hwnd As Integer
'UPGRADE_WARNING: Add a delegate for AddressOf fEnumWindowsCallBack Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'
Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)
End Function
This code is setup to check the process's running and match them to the process I have started using CreateProcess by the PID#. The error I am having trouble understanding in the upgrade is the AddressOf Operator. Again thanks for any help!
Last edited by dsc_chris; Jul 24th, 2004 at 04:17 AM.
-
Jul 21st, 2004, 08:54 PM
#2
Thread Starter
Member
-
Jul 24th, 2004, 04:17 AM
#3
Thread Starter
Member
Forget it, I found a better way of doing this in VB.net. Thanks for no replies :/
-
Jul 24th, 2004, 05:03 AM
#4
Fanatic Member
Just a friendly tip - its nice to say what you did to fix it. This post is no use to anyone
-
Jul 24th, 2004, 05:09 AM
#5
Thread Starter
Member
Not a problem, Instead of using EnumWindows API Calls, I used the Process.* which is in VB, Here is some "Sample" Code
VB Code:
Public Sub StatusCheck()
Dim DarkProcesses As Process() = Process.GetProcesses()
Dim Processes As Process
lstPids.Items.Clear()
For Each Processes In DarkProcesses
lstPids.Items.Add(Processes.Id.ToString)
Next
If lstPids.Items.Contains(lblPid.Text) Then
lblStatus.Text = "Status: Running"
Else
lblStatus.Text = "Status: Not Running. Attempting Restart"
If txtProcess.Text = "" Then
lblStatus.Text = "Status: Please type a program to run!"
Else
lblStatus.Text = "Status: Attempting to Re-Run Program!"
End If
End If
End Sub
Using VB.Net's process management i was able to get a list of running process's and compare my pid from the Process.Id call to the ones in the list box. Now if I could do this in an array I would, I already have it on the test table for the array my only issue is actually getting that array to clear and reset. Here is some sample code for that as well
VB Code:
Public Sub StatusArray()
Dim DarkProcesses As Process() = Process.GetProcesses
Dim Processes As Process
Dim pid As New ArrayList
Dim i As Integer
Dim bRunning As String
For Each Processes In DarkProcesses
pid.Add(Processes.Id.ToString)
'MsgBox("Found Process ID: " & Processes.Id.ToString)
Next
Dim idx As Integer = pid.BinarySearch(lblPid.Text)
If idx > 0 Then
'lblStatus.Text = "Status: w00t Running"
MsgBox("Running")
pid.Clear()
Else
MsgBox("Not Running")
pid.Clear()
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|