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
bostonsteAsked:
Who is Participating?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.