Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process switching

Status
Not open for further replies.

Millzy01

Programmer
Jan 11, 2007
20
GB
Hi, I have a application that looks for a running process and if it doesnt find it starts it (System.Diagnostics.process.start), however if the process is running i want to set it as the active window and i cant seem to find out how to do it.
so if anyone knows them please post a reply.
 
I'm assuming your using a process object (ex Dim p as Process).

Use the following function:
Code:
Private Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd As IntPtr) As Integer

The just call it like this (where p is the target Process object):
Code:
SetForegroundWindow(p.MainWindowHandle)

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top