Solved

Problem with process.getprocessbyname

Posted on 2008-10-08
8
536 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now