KB-68628: Bringing a program at runtime to the foreground.

Question:

When a program is at run time, can I give it focus and bring it to the foreground via scripts?

Solution:

Yes. To do so, use the script below:

Sub CommandButton1_Click()
‘Using Viewer method: ExecuteExternalApp
Set Service = GetObject(“winmgmts:”)

strProgramPath = “C:\Windows\system32\calc.exe”

For Each Process in Service.InstancesOf(“Win32_Process”)
If Process.Name = “calc.exe” Then
running = True
End If
Next

If running Then
 MsgBox “Calculator is already being executed!”

Set WshShell = CreateObject(“WScript.Shell”)
WshShell.AppActivate “calculator”
newkeys = “% R”    ‘Maximiza objeto ativo
 WshShell.SendKeys newkeys
Else
 Application.ExecuteExternalApp strProgramPath, “”, “”, 1    ‘Can be replaced by objShell.Run strProgramPath
End If

End Sub

NOTE: You can also issue this command with  Shell object (see the application attached to this article).

Attachments:

OpenProg.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *