Solved

keep a windows script open on windows 7

Posted on 2013-12-14
1
224 Views
Last Modified: 2013-12-16
i have created a com object that raises events.  one of the ways shown to test this is with a vbscript run by WScipt.exe.

the problem is that the script will exit before any events are raised .. before the sub that handles the event.  how can i keep the script open long enough to get the events?

i am calling the script from a command prompt:  wscript.exe test.vbs


here is my code;
set obj = WScript.CreateObject("TestApp.Agent", "agent_")

MsgBox "Value from Init is " & obj.Init
MsgBox "Status: " + obj.StatusMesssage
MsgBox "New Session Id: " + obj.NewSessionId
MsgBox "Len: " + CStr(Len(obj.NewSessionId))

if Len(obj.NewSessionId) > 0 then
	obj.Monitor
end if


Sub agent_AgentEvent(val)
     MsgBox "Event fired - val is " & val
End Sub

Open in new window

0
Comment
Question by:dhenderson12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39718973
You'll have to implement a waiting loop, endless or with a stop condition:
Dim obj, bQuit

set obj = WScript.CreateObject("TestApp.Agent", "agent_")

MsgBox "Value from Init is " & obj.Init
MsgBox "Status: " + obj.StatusMesssage
MsgBox "New Session Id: " + obj.NewSessionId
MsgBox "Len: " + CStr(Len(obj.NewSessionId))

if Len(obj.NewSessionId) > 0 then
	obj.Monitor
end if

bQuit = false
do
  WScript.Sleep 100
loop until bQuit

Sub agent_AgentEvent(val)
     MsgBox "Event fired - val is " & val
     bQuit = true
End Sub

Open in new window

0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question