KB-34941: Executing an external program when the domain starts.

Question:

How can I execute an application when the domain starts, even if there is no open E3Viewer?

Solution:

To do so, just place the following script at an Internal Tag’s OnStartRunning event:

Set WshShell = CreateObject(“WScript.Shell”)
WshShell.Run “c:\AppE3\application.exe”

That way, it will be executed whenever the domain starts.

However, to finish this process when the domain stops, you will need to know the PID (ProcessID) created for it after WshShell.Run has been executed. After this information has been retrieved, you must edit the script above as follows:

WshShell.Run “c:\AppE3\application.exe”
ProcessName = “application.exe”
Set service = GetObject(“winmgmts:\\.\root\cimv2″)
Set results = service.ExecQuery(” Select * from Win32_Process where Name = ” & ProcessName)
if results.count <> 0 then
for each obj in results
TagInternoProcessID = obj.ProcessId
exit sub
next
end if

Then, to finish the PID, you must create the following script at an Internal Tag’s OnStopRunning event:

Set service = GetObject(“winmgmts:\\.\root\cimv2″)
Set results = service.ExecQuery(” Select * from Win32_Process where ProcessId ='” & TagInternoProcessID & “‘”)
for each obj in results
obj.Terminate()
exit sub
next

NOTE: please review your script, setting up the necessary variables and links for the Internal Tag.

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 *