Solved

Problem with process.getprocessbyname

Posted on 2008-10-08
8
554 Views
Last Modified: 2012-05-05
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
Comment
Question by:bostonste
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Assisted Solution

by:ladarling
ladarling earned 200 total points
ID: 22672310
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
 
LVL 6

Expert Comment

by:wwnosal
ID: 22672375
Hmm This works for me:
 Dim p() As Process
    p = Process.GetProcessesByName("notepad")
0
 

Author Comment

by:bostonste
ID: 22672447
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:bostonste
ID: 22672463
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 22672493
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
 
LVL 6

Expert Comment

by:wwnosal
ID: 22672502
I think the problem is with your declaration..
Try like this:
 Dim p() As System.Diagnostics.Process

and then assign...
0
 

Author Closing Comment

by:bostonste
ID: 31504379
Chaps
Thank you all
Its so easy when you know how isnt it :)
0
 
LVL 11

Expert Comment

by:ladarling
ID: 22673012
Type inference is a great thing... I dont know why people hesitate to use it :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question