Jump to content

Recommended Posts

Posted

Hi!

I wrote a script that is processing files.

What I am basically doing is to monitor for event creation (see below):

;----------------------------------------------

$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colMonitoredEvents = $objWMIService.ExecNotificationQuery _

("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE " _

& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _

& "TargetInstance.GroupComponent= " _

& "'Win32_Directory.Name=""" & $SourceFolder & """'")

followed by an infinite loop

While 1

$objLatestEvent = $colMonitoredEvents.NextEvent

$FileName2 = $objLatestEvent.TargetInstance.PartComponent

; ....

; code for processing the files

; ....

WEnd

;--------------------------------------------------------------

The problem is that I cannot find a way to terminate this script -other than killing the task.

I tried to use something like this:

;--------------------------------------------------------------

TraySetClick(16)

$exititem = TrayCreateItem("Exit")

TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

Func ExitScript()

Exit

EndFunc

;--------------------------------------------------------------

But this code will work only after I will drop a new file in the source folder ($SourceFolder).

Are there any other ways I can exit the script?

TIA,

Don

Posted

You could always register a hotkey at the top of the script.

Richard:

Thank you very much for your reply.

I tried and I got the same result.

The script will stop and wait for the event (new file)

on line 2 (see below)

1 While 1

2 $objLatestEvent = $colMonitoredEvents.NextEvent

3 $FileName2 = $objLatestEvent.TargetInstance.PartComponent

4 ...

5 WEnd

It will exit only if I will drop a file in that folder.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...