Results 1 to 4 of 4

Thread: Closing programs code isn't behaving correctly

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Closing programs code isn't behaving correctly

    hey. I'm having some trouble with the code to close programs. heres what I have for my code so far:

    Dim px() As Process = System.Diagnostics.Process.GetProcesses 'gets processes running

    'gets number of DuckySE processes
    For Each Proc As Process In px 'loops through all processes, finding the name we want
    If Proc.ProcessName = "myProgram" And Not Proc.MainWindowHandle.ToInt32 = Me.Handle.ToInt32 Then 'used so doesnt close self
    Proc.CloseMainWindow()
    End If
    Next

    The problem is that it only closes some of the time! When I have this in a command button, it can find all the processes but it just doesn't close them. I dont have anything thats preventing it from closing in the form_closing of the applications either. Does the window have to be infocus or something? any ideas? .kill() works, but id like the other other one to work cause then it closes correctly....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Closing programs code isn't behaving correctly

    Assuming that there is nothing in your app that would prevent it closing then this should work.
    VB Code:
    1. Dim myProcID As Integer = Process.GetCurrentProcess.Id
    2.  
    3.         For Each proc As Process In Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
    4.             If proc.Id <> myProcID Then
    5.                 proc.CloseMainWindow()
    6.             End If
    7.         Next proc
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: Closing programs code isn't behaving correctly

    ok thanks. I tried that and it still doesnt work! The only code I have in the form_closing is: trayicon1.visible = false. Still no luck. It works though with the .kill(). I want to use the other one though because then it will hide the icon. Any ideas?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: Closing programs code isn't behaving correctly

    ok I just realized why it doesnt work. My apps are set up to now show in the taskbar! I want it that way though. Anyway to get this to work wihtout having the programs show in the taskbar?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width