Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Prevent a .NET program for starting if the .exe is in us
Message
From
24/03/2017 09:38:31
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01649285
Message ID:
01649294
Views:
32
>Hi Bill,
>
>in a vb.net-program I use the following code to see, if a program is already started and then activate it instead of starting a new instance, may it can help you.
>
>Best regards
>
>Thomas
>
>
>            Dim nProcessID As Integer = 0
>            Dim tempprocess As Process
>            tempprocess = checkInstance()
>            If Not tempprocess Is Nothing Then
>                nProcessID = tempprocess.Id
>                AppActivate(nProcessID)
>
>                'MsgBox("Läuft schon")    ' means "Already running"
>                End
>            End If
>        Else
>            Dim cText As String = My.Computer.Clipboard.GetText
>            oData = getclipclassic(cText)
>            ' MsgBox(oData.Count)
>        End If
>...................
>   Public Function checkInstance() As Process
>        Dim cProcess As Process = process.GetCurrentProcess()
>        Dim aProcesses() As Process = process.GetProcessesByName(cProcess.ProcessName)
>        'loop through all the processes that are currently running on the 
>        'system that have the same name
>        For Each process As Process In aProcesses
>            'Ignore the currently running process 
>            If process.Id <> cProcess.Id Then
>                'Check if the process is running using the same EXE as this one
>                If Reflection.Assembly.GetExecutingAssembly().Location = cProcess.MainModule.FileName Then
>                    'if so return to the calling function with the instance of the process
>                    Return process
>                End If
>            End If
>        Next
>
>
>
>        'if nothing was found then this is the only instance, so return null
>        Return Nothing
>    End Function
>
>    Public Function getCombookProcessId() As Integer
>        Dim cComBook As String = "ComBook"
>        Dim cPName As String = ""
>        Dim nRet As Integer = 0
>        Dim aP() As Process = Process.GetProcesses
>        For Each Process As Process In aP
>            cPName = Process.MainWindowTitle.ToUpper
>            If cPName.IndexOf("COMBOOK") > -1 Then
>                nRet = Process.Id
>            End If
>        Next
>        Return nRet
>    End Function
>
Thank you, Thomas
I'll take a look
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Reply
Map
View

Click here to load this message in the networking platform