Solved

keep a windows script open on windows 7

Posted on 2013-12-14
1
218 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
1 Comment
 
LVL 68

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

So many times I have seen the words written in a question "if only I could show you" or " I know how hard it is for you since you can't see it" in any zone. That has inspired me to write about this tool in windows 7 called "Problem Steps Recorder…
OfficeMate Freezes on login or does not load after login credentials are input.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now