-
Jun 12th, 2021, 03:27 PM
#1
Thread Starter
Hyperactive Member
Running time of Active Application...
Hello,
I am wondering if it is possible to get the name of active application and its start time.
I have used following code to get all process but not sure how to get current active process and its start time.
Will be thankful for any responses.
Code:
Dim myProcessList As Process() = Process.GetProcesses
For Each myProcess As Process In myProcessList
If myProcess.MainWindowTitle <> "" Then
Dim myListView As ListViewItem = ListView1.Items.Add(myProcess.MainWindowTitle)
myListView.SubItems.Add("running")
End If
Next
-
Jun 13th, 2021, 02:46 AM
#2
Re: Running time of Active Application...
Try this...
Code:
Dim proc As Process = Process.GetCurrentProcess
Dim ts As TimeSpan = Now - proc.StartTime
MsgBox($"Uptime = {ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds}")
Last edited by .paul.; Jun 13th, 2021 at 02:49 AM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2021, 09:37 AM
#3
Thread Starter
Hyperactive Member
Re: Running time of Active Application...
Hello Paul,
Thank you for your response.
Tried the same but I am getting "Form1" only even if I bring some other app - say Notepad into foreground.
Here is my sample logic..
thanks
Code:
Private Sub GetActiceProcess()
ListView1.Items.Clear()
Dim myProcess As Process = Process.GetCurrentProcess
Dim myTs As TimeSpan = Now - myProcess.StartTime
Dim myTime As Long = myTs.TotalSeconds
Dim myListItem As ListViewItem = ListView1.Items.Add(myProcess.MainWindowTitle.ToString)
myListItem.SubItems.Add(myProcess.StartTime)
myListItem.SubItems.Add(myTime)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Call GetActiceProcess()
End Sub
[/QUOTE]
-
Jun 13th, 2021, 10:17 AM
#4
Re: Running time of Active Application...
Code:
Dim myProcessList As Process() = Process.GetProcesses
For Each myProcess As Process In myProcessList
If myProcess.MainWindowTitle <> "" Then
Dim myListView As ListViewItem = ListView1.Items.Add(myProcess.MainWindowTitle)
myListView.SubItems.Add("running")
Dim myTs As TimeSpan = Now - myProcess.StartTime
Dim myTime As Long = myTs.TotalSeconds
' add to listview, or whatever
End If
Next
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2021, 10:21 AM
#5
Thread Starter
Hyperactive Member
Re: Running time of Active Application...
Hi Paul,
I am able to read all running processes without any problem; the challenge I have is to read the current process or active process that a user is currently active on.
thanks...
Originally Posted by .paul.
Code:
Dim myProcessList As Process() = Process.GetProcesses
For Each myProcess As Process In myProcessList
If myProcess.MainWindowTitle <> "" Then
Dim myListView As ListViewItem = ListView1.Items.Add(myProcess.MainWindowTitle)
myListView.SubItems.Add("running")
Dim myTs As TimeSpan = Now - myProcess.StartTime
Dim myTime As Long = myTs.TotalSeconds
' add to listview, or whatever
End If
Next
-
Jun 13th, 2021, 04:09 PM
#6
Re: Running time of Active Application...
Code:
Public Declare Function GetActiveWindow Lib "user32.dll" () As IntPtr
Code:
Dim proc As Process = Process.GetProcessById(CInt(GetActiveWindow))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|