Obtaining complete file name from tsk manager

Answered Obtaining complete file name from tsk manager

  • Monday, April 09, 2012 5:12 AM
     
     
    Hey guys

    There is Notepad opened.

    How can I display the full application name from the taskbar into label1.text.

    For Example:

    Label1.text = Untitled - Notepad
    or
    Label1.text = Whatever - Notepad

    Can I check the applications if they contain the word "Notepad" and if they do then display the whole name in label1.text?


    Thanks

All Replies

  • Monday, April 09, 2012 5:22 AM
     
     

    Use the Process class to get the name of all processes, and then examine the names to determine the one you want.  The problem is going to be knowing the one you want, as there could be any number of processes that contain a particular string.  You may wish to explain your problem in a little more detail.

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
    http://msdn.microsoft.com/en-us/library/1f3ys1f9.aspx
    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.processname.aspx

  • Monday, April 09, 2012 8:20 AM
     
     Answered Has Code

    That looks like the MainWindowTitle property to me. In that case, something like this should do the trick:

    Process.GetProcessesByName("Notepad")(0).MainWindowTitle

    However, that's not accurate, as you don't know which notepad you're getting the title of this way, so perhaps you use the PID to your advanage? 

    Process.GetProcessById(PID_HERE).MainWindowTitle

    Or use a Process handle?

    Process.GetProcesses().Where(Function(x) x.Handle = hID)(0).MainWindowTitle

    Where hID is the Proc Handle you're looking for as IntPtr.

    Cheers :)


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum

  • Monday, April 09, 2012 11:46 AM
     
      Has Code

    Just to supplement the answers you've already gotten, here is  quick function that lets you lookup given process name and check if its running or not..

    Private Function GetProcesses(ByVal nameOfProcess As String) As Integer
        Dim namedProcess As Process() = Process.GetProcessesByName(nameOfProcess)
        Return namedProcess.count
    End Function


    • Edited by Untouchab1e Tuesday, April 10, 2012 6:24 AM count, not toString
    •  
  • Monday, April 09, 2012 12:10 PM
     
      Has Code

    Just to supplement the answers you've already gotten, here is  quick function that lets you lookup given process name and check if its running or not..

    Private Function GetProcesses(ByVal nameOfProcess As String) As Integer
        Dim namedProcess As Process() = Process.GetProcessesByName(nameOfProcess)
        Return namedProcess.ToString
    End Function

    This is not compliable. The function returns an Integer where ToString returns a String. Maybe you intended to Return namedProcess.Count

    Enable Option Strict On to avoid inappropriate data handling.


    Armin

  • Tuesday, April 10, 2012 1:28 AM
     
      Has Code

    Just to supplement the answers you've already gotten, here is  quick function that lets you lookup given process name and check if its running or not..

    Private Function GetProcesses(ByVal nameOfProcess As String) As Integer
        Dim namedProcess As Process() = Process.GetProcessesByName(nameOfProcess)
        Return namedProcess.ToString
    End Function

    This is also slightly irrelevant, as he wanted to not return the count of processes, but the title of a specific process. In your case the function should have been something like:

    Private Function GetProcesseCount(ByVal nameOfProcess As String) As Integer
    	Dim count As Integer = Process.GetProcessesByName(nameOfProcess).Count()
    	Return count
    End Function

    As the way you do it, you're defining a Process array (Process()), returning that array as a string, and telling the function that it's meant to return a value of integer all at the same time. Lots of discrepancies here.


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum

  • Tuesday, April 10, 2012 6:23 AM
     
     
    You are quite right. I messed up the Return statement, updated the post now to get the count instead.
    • Edited by Untouchab1e Tuesday, April 10, 2012 6:23 AM count != length
    •  
  • Tuesday, April 10, 2012 11:05 AM
     
     
    You are quite right. I messed up the Return statement, updated the post now to get the count instead.
    Thx. :) However, Length is preferrable for an array. Count is an Extension method. (Though no need to change it again as it works)

    Armin