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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Focus to an open application

Status
Not open for further replies.

sk2107c

Programmer
May 2, 2017
22
0
0
JO
Hi,

I have this code to run and application (notepad for example) and if it is already running I want to set focus on it.
Code:
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
strQuery = "Select * from Win32_Process"
Set ColItems = objWMIService.ExecQuery(strQuery,,48)
For Each objItem In colItems
	If UCase(objItem.name)=UCase("notepad.exe") Then
	        msgbox objItem.name & " already running"
[highlight #FCE94F]'-------- Here I want to set focus on the Open notepad window ------[/highlight]
		WScript.Quit
	End If
Next
objShell.run "notepad.exe"

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top