Determine whether the program is running and whether the program is running
In the recent period, you need to write a small function to determine whether the program is running.
After a program is installed, it may be run by multiple users. So how can we determine that the current user has run this program?
The following is how Insus. NET works:
VB. NET WinForm get running program user name http://www.cnblogs.com/insus/p/5194839.html
Then:
WinForm (VB. NET) Get the username of the current login http://www.cnblogs.com/insus/p/5195126.html
From the above method, if the values are the same, the program has been run by the current user.
Source code:
Public Shared Function IsRunning (processName As String) As Boolean Dim btnIsRun As Boolean = False Dim owner As String = GetProcessOwner (App) Dim po As String = owner. substring (owner. lastIndexOf ("\") + 1) Try Dim listProc () As System. diagnostics. process listProc = System. diagnostics. process. getProcessesByName (processName) If listProc. length> 0 AndAlso GetUserName () = po Then btnIsRun = True Else btnIsRun = False End If Catch ex As Exception btnIsRun = False End Try Return btnIsRun End FunctionView Code