d1r Posted December 17, 2007 Posted December 17, 2007 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
Richard Robertson Posted December 18, 2007 Posted December 18, 2007 You could always register a hotkey at the top of the script.
d1r Posted December 18, 2007 Author Posted December 18, 2007 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 12 $objLatestEvent = $colMonitoredEvents.NextEvent3 $FileName2 = $objLatestEvent.TargetInstance.PartComponent 4 ...5 WEndIt will exit only if I will drop a file in that folder.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now