Results 1 to 5 of 5

Thread: [Resolved] n00b to VB.NET need help.

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    37

    [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:
    1. Public oIE As Object
    2.     Public glPid As Integer
    3.     Public glHandle As Integer
    4.     Public colHandle As New Collection
    5.     Public glHwnd As Integer
    6.    
    7.     Public Const SMTO_BLOCK As Short = &H1s
    8.     Public Const SMTO_ABORTIFHUNG As Short = &H2s
    9.     Public Const WM_NULL As Short = &H0s
    10.     Public Const WM_CLOSE As Short = &H10s
    11.     Public Const WM_DESTROY As Short = &H2s
    12.     Public Const PROCESS_ALL_ACCESS As Integer = &H1F0FFF
    13.    
    14.    
    15.    
    16.     'UPGRADE_ISSUE: Declaring a parameter 'As String' is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1016"'
    17.     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
    18.     Declare Function GetParent Lib "user32" (ByVal hwnd As Integer) As Integer
    19.     Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
    20.     Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
    21.     Declare Sub ReleaseCapture Lib "user32" ()
    22.     Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessID As Integer) As Integer
    23.    
    24.     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
    25.    
    26.     Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Integer, ByVal uExitCode As Integer) As Integer
    27.    
    28.  
    29.     Public Function fEnumWindowsCallBack(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
    30.         Dim lParent As Integer
    31.         Dim lThreadId As Integer
    32.         Dim lProcessId As Integer
    33.        
    34.         fEnumWindowsCallBack = 1
    35.         lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)
    36.        
    37.         If glPid = lProcessId Then
    38.             glHwnd = hwnd
    39.             fEnumWindowsCallBack = 0
    40.             lParent = GetParent(hwnd)
    41.             If lParent = 0 Then
    42.                 colHandle.Add(hwnd)
    43.             End If
    44.         Else
    45.         End If
    46.        
    47.     End Function
    48.    
    49.    
    50.  
    51.    
    52.     Public Function fEnumWindows() As Boolean
    53.         Dim hwnd As Integer
    54.  
    55.         'UPGRADE_WARNING: Add a delegate for AddressOf fEnumWindowsCallBack Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'
    56.         Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)
    57.     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.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    37
    Anyone?

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    37
    Forget it, I found a better way of doing this in VB.net. Thanks for no replies :/

  4. #4
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    Just a friendly tip - its nice to say what you did to fix it. This post is no use to anyone

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    37
    Not a problem, Instead of using EnumWindows API Calls, I used the Process.* which is in VB, Here is some "Sample" Code


    VB Code:
    1. Public Sub StatusCheck()
    2.         Dim DarkProcesses As Process() = Process.GetProcesses()
    3.         Dim Processes As Process
    4.  
    5.  
    6.         lstPids.Items.Clear()
    7.         For Each Processes In DarkProcesses
    8.             lstPids.Items.Add(Processes.Id.ToString)
    9.         Next
    10.         If lstPids.Items.Contains(lblPid.Text) Then
    11.             lblStatus.Text = "Status: Running"
    12.         Else
    13.             lblStatus.Text = "Status: Not Running. Attempting Restart"
    14.             If txtProcess.Text = "" Then
    15.                 lblStatus.Text = "Status: Please type a program to run!"
    16.             Else
    17.                 lblStatus.Text = "Status: Attempting to Re-Run Program!"
    18.             End If
    19.         End If
    20.     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:
    1. Public Sub StatusArray()
    2.         Dim DarkProcesses As Process() = Process.GetProcesses
    3.         Dim Processes As Process
    4.         Dim pid As New ArrayList
    5.         Dim i As Integer
    6.         Dim bRunning As String
    7.         For Each Processes In DarkProcesses
    8.             pid.Add(Processes.Id.ToString)
    9.             'MsgBox("Found Process ID: " & Processes.Id.ToString)
    10.         Next
    11.  
    12.         Dim idx As Integer = pid.BinarySearch(lblPid.Text)
    13.  
    14.  
    15.  
    16.         If idx > 0 Then
    17.             'lblStatus.Text = "Status: w00t Running"
    18.             MsgBox("Running")
    19.             pid.Clear()
    20.         Else
    21.             MsgBox("Not Running")
    22.             pid.Clear()
    23.         End If
    24.     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
  •  



Click Here to Expand Forum to Full Width