Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:41:12+00:00 2026-06-11T10:41:12+00:00

In my application I allow for the users to add a program from a

  • 0

In my application I allow for the users to add a program from a open file dialog, and it then adds the item to a listview and saves the items location into the tag. So what I am trying to do is when the program in the listview is selected and the button is pressed, it starts a timer and this timer checks to see if the process is running, and if it isn’t launches the process, and once the process is launched it gets the window title of the process and sends it to a textbox on another form.

EDIT:
The question is if anyone can see why it is not working, by this I mean starting the process, then when it’s started closing the form and adding the process window title to a textbox on another form.
I have tried to get it working but I can’t. I know that the process name it is getting is right I think my problem is to do with my for loop. Basically it isn’t doing anything visible right now.

I feel like I am very close with my code and im hoping it just needs a couple minor tweaks. Any help would be appreciated. Sorry if my coding practices aren’t that great, im pretty new to this.

**EDIT:I found solution. I added code to the button that enables my timer to execute the process. Also another problem was indeed the way it read the file, I had to use the replace function to remove the “.exe” from the filepath code.

EDIT 2 : A better solution has been posted by Mark Hall. I am now using his code as it has less chance for error.

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       Dim s As String = ListView1.SelectedItems(0).Tag
    Dim myFile As String = Path.GetFileName(s)
    Dim mu As String = myFile.Replace(".exe", "").Trim()
    Dim f As Process
    Dim p As Process() = Process.GetProcessesByName(mu)

    For Each f In p
        If p.Length > 0 Then
            For i As Integer = 0 To p.Length - 1
                ProcessID = (p(i).Id)
                AutoMain.Name.Text = f.MainWindowTitle
                Timer1.Enabled = False
                Me.Close()
            Next
        Else
            ProcessID = 0
            End If
        If ProcessID = 0 Then
            Process.Start(mu)
        End If
    Next
    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:41:13+00:00Added an answer on June 11, 2026 at 10:41 am

    What is happening is that you are looking for a Process that matches your parameters before you enter your For Each loop the Process array is empty so it never enters it, therefore you never start your process.

    This is a very quick example that works:

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim s As String = ListView1.SelectedItems(0).Tag.ToString
        Dim myFile As String = Path.GetFileName(s)
    
        Dim p As Process() = Process.GetProcessesByName(Path.ChangeExtension(myFile, Nothing))
        Static started As Boolean
    
        If p.Count > 0 Or started Then
            If p.Length > 0 Then
                For i As Integer = 0 To p.Length - 1
                    ProcessId = (p(0).Id)
                    AutoMain.Name.Text = p(0).MainWindowTitle
                    Timer1.Enabled = False
                    started = False
                    Timer1.Stop()
                    Me.Close()
                Next
            Else
                ProcessId = 0
            End If
        Else
            started = True
            Process.Start(myFile)
        End If
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that allow users to choose picture from native gallery then
We're using the file picker dialog to allow users to add documents into our
I want to allow users of my application to add sub-users and set privileges
To allow users and site admins to view/add/edit/delete data in my application I decided
I am writing a PHP application that's supposed to allow users to add certain
I'm creating rails application where it allow users to add geo-location data for restaurants,
In a C# program I'd like to allow users to specify a sound file
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,
I'm working on an application that allows users to add their own RSS feeds
Our application uses SQL Server Reporting Services and allows users to add custom filters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.