Solved

keep a windows script open on windows 7

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
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…

679 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