Timer to turn off automated task – Update

Welcome Forums General PowerShell Q&A Timer to turn off automated task – Update

Viewing 7 reply threads
  • Author
    Posts
    • #262706
      Participant
      Topics: 12
      Replies: 40
      Points: 170
      Rank: Participant

      I have an automated folder polling task running which I need to run only for a predetermined time and then turn off while I take the changed contents of the folder and perform a Move-Item command to the same. Can someone help me with the timer portion of the script please?

      Update:  I have everything working.   I just need a way to stop the polling function from running after the script has executed once….. PERIOD.

      I assume it will be a command at the end of the script as the last line

      Thank you

      • This topic was modified 6 days, 22 hours ago by nal2us224.
    • #262742
      Participant
      Topics: 16
      Replies: 1792
      Points: 3,290
      Helping Hand
      Rank: Community Hero
    • #262748
      Participant
      Topics: 12
      Replies: 40
      Points: 170
      Rank: Participant

      Forgive my amateur use of the term “polling” Rob. Yes you are correct. I want to place a command at the end of the script I shared that causes the polling function to completely CEASE as the code I shared is part of a bigger script. Then the rest of the code will run and at the end of the script I will LOOP the entire script which will allow the code to run once more , then once again stop, until the next run of the script from the loop. Make sense Sir?

      The sample code from the link you shared seems to do the job except for one problem. The user STILL has to manually push CNTR + C to execute the unregister sequence.
      I need some sample code that will emulate the CNTR + C Keystroke in code without the use for manual input.

      Any Ideas?

      • This reply was modified 6 days, 21 hours ago by nal2us224.
    • #262772
      Participant
      Topics: 16
      Replies: 1792
      Points: 3,290
      Helping Hand
      Rank: Community Hero

      Forgive my amateur use of the term “polling” Rob. Yes you are correct. I want to place a command at the end of the script I shared that causes the polling function to completely CEASE as the code I shared is part of a bigger script. Then the rest of the code will run and at the end of the script I will LOOP the entire script which will allow the code to run once more , then once again stop, until the next run of the script from the loop. Make sense Sir?

      Does not make sense. The code is “Watch directory C:\Temp for changes and do this when changes are detected”. What would occur that you would like to stop watching the directory? Emulating key presses are a bad practice and most likely unnecessary. When you are doing send keys, it is an absolute last resort and still cannot ensure it’s going to work. There are multiple threads all going around the same solution. Have you provided exactly what you are trying to accomplish? For instance, if you wanted to once an hour process a directory, FileWatcher is not the solution. FileWatcher is basically to continually watch a directory or file and immediately do something, typically as long as the server is up. Filewatcher would be a startup script or task and it would run processing files like a queue.

    • #262775
      Participant
      Topics: 12
      Replies: 40
      Points: 170
      Rank: Participant

      Ok Rob understood and thank you for that clarification. Having said that if “File Watcher” is NOT the solution can you provide a sample of what would be a viable solution? I only need to scan the folder once per run, keep the scan active for a predetermined period of time and then cease that operation.

      Please advise.

      Thank you Sir for your valuable input!!!

    • #262778
      Participant
      Topics: 16
      Replies: 1792
      Points: 3,290
      Helping Hand
      Rank: Community Hero

      I only need to scan the folder once per run, keep the scan active for a predetermined period of time and then cease that operation.

      That is a bit contradictory, either you are processing one time or you want to keep processing for a specified amount of time. Look at this example:

      This would process the directory 5 times with a 5 second timeout, which would be approx 25 seconds as we are not processing anything. The sleep could be and timeout count would be incremented to adjust how many time the directory is processed in a given time.

      • This reply was modified 6 days, 19 hours ago by Rob Simmers.
    • #262784
      Participant
      Topics: 12
      Replies: 40
      Points: 170
      Rank: Participant

      Thank you very much and have a blessed day!!!

    • #262799
      Participant
      Topics: 12
      Replies: 40
      Points: 170
      Rank: Participant

      That script is beautiful Rob. It is exactly what I needed. Thank you so much!!!!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.