[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

Problem with process.getprocessbyname

I have this sub to check if somthing is running

  Sub OnCreated(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
        'MessageBox.Show("On Created")
        Dim programName As String = "notepad"
        Dim p() As process = process.GetProcessesByName(programName)
        If p.Length > 0 Then
            Exit Sub
        Else
            If IO.File.Exists("C:\Program Files\Portland Software\Primopost\scanner.exe") Then
                System.Diagnostics.Process.Start("C:\Program Files\Portland Software\Primopost\scanner.exe")
            End If
        End If
    End Sub

The problem i have is that      process.GetProcessesByName(programName) is not a member of process
Can any one tell me what i need to do to sort it out
0
bostonste
Asked:
bostonste
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
ladarlingCommented:
Have you tried to fully qualify the function?
Dim p = System.Diagnostics.Process.GetProcessesByName(programName)
If that does not work, could you post the error you are getting or screenshot, perhaps?
 
0
 
wwnosalCommented:
Hmm This works for me:
 Dim p() As Process
    p = Process.GetProcessesByName("notepad")
0
 
bostonsteAuthor Commented:
Here is a screen shot, it must be somthing to do with the type of sub it is in but i cant see what it is
Doc1.doc
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
bostonsteAuthor Commented:
i need to be able to see if somthing is running here, any ideas of a better way if if the get process doesnt work
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It will work...the problem is you have added a Reference to something that also has a class called "Process" and the compiler can't figure out which one you want.

So ladarling was right and you just need to fully qualify both sides of the equals "=" sign.     =)

Change this:

    Dim p() As process = process.GetProcessesByName(programName)
   
To this:

    Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(programName)
0
 
wwnosalCommented:
I think the problem is with your declaration..
Try like this:
 Dim p() As System.Diagnostics.Process

and then assign...
0
 
bostonsteAuthor Commented:
Chaps
Thank you all
Its so easy when you know how isnt it :)
0
 
ladarlingCommented:
Type inference is a great thing... I dont know why people hesitate to use it :-)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now