Solved

keep a windows script open on windows 7

Posted on 2013-12-14
1
223 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

738 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