[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Check if app is running on the device

I'm looking for a VB .NET code that would run on a device to check if a specific application is running on the device. Thank you!
0
EwS
Asked:
EwS
1 Solution
 
ptakjaCommented:
What kind of device? Standard PC or a PocketPC?
0
 
ptakjaCommented:
Here's some code I use to do this for standard Windows apps...

    ' ****************************************************************************************
    ' AppIsAlreadyRunning
    ' ABSTRACT: Function checks if this application is already running in another thread.
    '
    ' ****************************************************************************************
    Private Function AppIsAlreadyRunning() As Boolean
        ' Get the filename of the main module
        Dim moduleName As String = Process.GetCurrentProcess.MainModule.ModuleName

        ' Discard the extension to get the process name
        Dim procName As String = System.IO.Path.GetFileNameWithoutExtension(moduleName)

        ' Return true if there are 2 or more processes with that name
        If Process.GetProcessesByName(procName).Length > 1 Then
            Return True
        End If
    End Function

Note that this WON'T work for Compact Framework applications since the Compact Framework doesn't support the Process class (or very little of it anyway).
0
 
ptakjaCommented:
Speaking of PocketPC apps, the PocketPC OS is not supposed to let an app launch more than one instance of itself. If an app is already running and the user taps the app's icon, the OS simply re-activates that app.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
EwSAuthor Commented:
ptakja,
I'm using Pocket PC. I just need a program RUNNING ON THE DEVICE to check if a specific application is running on the device.

"Note that this WON'T work for Compact Framework applications since the Compact Framework doesn't support the Process class (or very little of it anyway)." - That's exactly why your code doesn't work on the device.

0
 
NetworkArchitekCommented:
Apparently there is not a managed interface to do this, that I am aware of, however here is an MSDN article which creates a process manager using P/Invoke. It may take a little work to employ this in your application but it might give you a good start. Of course you're not interested in a process manager, but it demonstrates using P/Invoke to enumerate through all the processes and so forth.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/ProcessManager.asp
0
 
EwSAuthor Commented:
NetworkArchitek,
I've seen this article before, but how do I do it in VB? I need some code...
0
 
EwSAuthor Commented:
This is my function using OpenNETCF Smart Device Framework 1.2 that can be found on www.opennetcf.org/sdf:

Imports OpenNETCF.Toolhelp

    Public Shared Function IsAppRunning(ByVal appName) As Boolean

        Dim myProcesses() As ProcessEntry
        Dim instance As ProcessEntry
        myProcesses = ProcessEntry.GetProcesses()

        For Each instance In myProcesses
            If instance.ExeFile.Trim = appName Then
                Return False
            End If
        Next
        Return True
    End Function

Can I have my points refunded? - Thank you.
0
 
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now