Solved

Problem with process.getprocessbyname

Posted on 2008-10-08
8
545 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close tabpage of custom control 9 33
Ajax Panel Not Updating When Triggered By Timer 4 71
Set value of dynamically created checkboxlist 2 31
Disable extension 8 36
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

813 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

17 Experts available now in Live!

Get 1:1 Help Now