Hi,

I have a problem with my code. I am checking for the application instance. When i run application A , application B also must run. Below is my code to check the Application B if it is not running i have to make sure the code below execute it. Application B is located at desktop.
I have problem with the code below. It seems doesn't work and i couldn't find where is the problem. Anyone can help me !!! Thank You.

Dim sPath As String = Application.StartupPath & "\APPLICATION B.exe"
            If Process.GetProcessesByName("APPLICATION B.exe").LongLength = 0 Then
                Debug.Print("1 sPath=>" & sPath)
                File.Exists(sPath)
                Debug.Print("2 sPath=>" & sPath)
                Dim ShellProcess As New Process
                ShellProcess.StartInfo.FileName = sPath
                Debug.Print("ShellProcess.StartInfo.FileName=>" & ShellProcess.StartInfo.FileName)
                ShellProcess.StartInfo.UseShellExecute = True
                Debug.Print("ShellProcess.StartInfo.UseShellExecute=>" & ShellProcess.StartInfo.UseShellExecute)
                ShellProcess.Start()
                Debug.Print("ShellProcess.Start=>" & ShellProcess.Start)
                ShellProcess.WaitForExit()
            End If
Dim sPath As String = String.Format("{0}{1}{0}", Chr(34), IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "APPLICATION B.exe"))
            If Process.GetProcessesByName("APPLICATION B.exe").Count = 0 Then
                Debug.Print("1 sPath=>" & sPath)
                File.Exists(sPath)
                Debug.Print("2 sPath=>" & sPath)
                Dim ShellProcess As New Process
                ShellProcess.StartInfo.FileName = sPath
                Debug.Print("ShellProcess.StartInfo.FileName=>" & ShellProcess.StartInfo.FileName)
                ShellProcess.StartInfo.UseShellExecute = True
                Debug.Print("ShellProcess.StartInfo.UseShellExecute=>" & ShellProcess.StartInfo.UseShellExecute)
                Dim isRunning As Boolean = ShellProcess.Start()
                Debug.Print("ShellProcess.Start=>" & isRunning)
                ShellProcess.WaitForExit()
            End If

hi,

Thank you for your guidance. I receive an error 'Count' is not a member of 'System.Array'
I have no idea what i have left out
Please guide!!!

>Count' is not a member of 'System.Array'

Add "using System.Linq;" if you are working on .net framework 3.5 or 4.0 (vs2008) or use Length property.

Thank YOu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.