הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, November 23, 2016 9:11 PM
I am pretty new to vb.net and programming in general.
I am trying to create a function that looks to see if a process is running for the current user only. So far I am able to check if the process is running just fine. But, if the process is running for a separate user, I will get a false positive.
Here is what i have so far:
Dim p() As Process
Private Sub CheckIfRunning(processname As String)
'processname = "SLDWORKS"
p = Process.GetProcessesByName(processname)
If p.Count > 0 Then
' Process is running
Console.WriteLine("Solidworks Is Running")
'Else boolstatus = False
boolstatus = True
Else
' Process is not running
Console.WriteLine("Solidworks Is Not Running")
boolstatus = False
End If
End Sub
All replies (3)
Wednesday, November 23, 2016 9:56 PM
I am trying to create a function that looks to see if a process is running for the current user only. So far I am able to check if the process is running just fine. But, if the process is running for a separate user, I will get a false positive.
There are two methods described here.
WMI is simpler - the time it takes is not likely to be an issue. You could convert that code using an on-line code converter, or just rewrite it in VB as query process is the only important bit.
Thursday, November 24, 2016 8:00 AM | 1 vote
Hi kodybr,
Thank you for posting in MSDN Forum.
Use the following code snippet you could find the processes for the current user.
Dim CurrentSessionID As Integer = Process.GetCurrentProcess.SessionId
For Each proc As Process In Process.GetProcesses
If proc.SessionId = CurrentSessionID Then
MessageBox.Show(proc.ProcessName & " is running as the currently logged on user")
End If
Next
And this thread is about list processes for the current user in VB. You could check and refer that if it helps.
Hope it will be helpful to you.
Best Regards,
Neda Zhang
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thursday, November 24, 2016 10:54 AM
You can see which users own a service (an executable is always only running for the current user).
However, a service (process) can also be started by other users and still be used by more persons.
AFAIK is in the OS no information available which processes are used by a more users at that moment.
Otherwise we would not every time if we close Windows since windows 7 see that message which tells that it is possible that other users are also busy. Sometimes they make at Microsoft lazy made software, but not on that level and not during such a long time.
Success
Cor