Stop a PowerShell script GUI while in a loop - loops

I have a PowerShell script for which I've done a GUI.
Every time a do or for loop is running the GUI becomes unresponsive and have to wait until it's done before I can close the GUI or press any other button.
The problem is anoying when for any number of reasons the loop runs infinitely and the only way to stop it is to kill PowerShell from task manager.
I've tried using break but this causes some sort java error although it stop and kills they gui...but I don't want to have the error.
If I use break in the script without GUI the script stops.
Is there a way to have the GUI responding when a loop is running and to stop the script when ever I what it to stop?

You could run the PowerShell script as a job and have the GUI polling the status of that job (in a loop with so you can still react on user input).
Cancelling a script is then also possible by just cancelling the job.

Related

How to keep a process (in this case scrnsave.scr” running on top of all other windows making them run in background?

I am attempting to keep the screen saver active manually for a predetermined amount of seconds so that I program can run in the background without displaying a bunch of trash data that it displays when it boots. In order to make a more seamless GUI for a kiosk
Currently I am running a batch script That turns off echo, manually start screensaver using the start command. Then I am using the time out function to set a predetermined amount of seconds until terminating the screensaver. I terminate the screensaver by using a visual basic script that outputs the up arrow key us ending the screensaver. Then I exit. Any ideas on how to keep this on top? I know that it is still running in the background if I exit the program really quickly I continue to see the countdown.

Automating Tortoise SVN Update Fails While User Execution Succeeds

I have a few files i want to make sure I keep up to date using Tortoise SVN. I've used commandline and also created a batch file and both run successfully when I user-execute them.
However, when I use Windows Task Scheduler to try and schedule an automation for the batch script, it doesn't run successfully; it just hangs and runs endlessly. The log file looks just the same whether using the automation or not. That said, I have to manually end the automation in task scheduler and then run an SVN cleanup command to remove the locks that remain on the file from the incomplete task.
What is causing this, and how do I make it so that the automation successfully runs and doesn't have the file-locking problem?
My back script's code is below:
svn update --accept theirs-conflict C:/MyFolder/myfile.R
For transparency, I've tried changing the option 'theirs-conflict' to other settings (and removing it completely). The symptoms are the same in every scenario.

EXE is not Executing from Schedule Task

My EXE is executing perfectly fine when I am executing it by double click on it, but it is not executing when I am trying to run it via Schedule Task.
I am running schedule task on a local machine as administrator. I have already set the following settings into the "Security Options" of the Schedule Task.
Run only when user is logged in (I am logged in when schedule task is running)
Run with highest privileges check box is checked
In my case, it didn't worked because of the start in location of the program.
Set the [Start in] (optional) properties of the scheduled task with the path where the exe file is exist.
The default [Start in] value is C:/Windows/System32
Depending on which Windows OS you're running this on, your EXE may have in fact started and is running in the background, with the user interface completely hidden. Depending on the EXE you are trying to run, it may be sitting there, hidden, waiting for user input that it will never get. If your EXE doesn't require any user input (something that just runs and then closes when it completes), then you might just check to see if the job is actually done.
A trick I have used to verify this is to create a small batch program like this:
#echo off
echo myEXE Scheduled Task Started %DATE% %TIME% >>c:\myEXE.log
myEXE.exe
echo myEXE Scheduled Task Completed %DATE% %TIME% >>c:\myEXE.log
Have your scheduled task call this batch script instead of myEXE directly. This will generate a text file (myEXE.log) that you can check to verify when the scheduled task kicked off, and then when (and whether) the EXE finished.
Just for kicks (and to test what I'm talking about) you can add these lines at the end of the batch script.
pause
echo Batch Script Finished %DATE% %TIME% >>c:\myEXE.log
If you never see the cmd window waiting for you to Press any key to continue... then you'll also never see the last line in your log file (myEXE.log)
Windows Task Scheduler is a strange beast of a program. It's not really a CRON like task scheduler and it's not a Quartz based program, other than relying on internal clock system.datetime, which has been known to have "issues" of its own.
Nevertheless, it can sometimes trip over itself (unproven, but from personal observations), when it comes to permissions of a task and who created it vs what account is used to run it.
I found the following steps gives me a "clean" task schedule every time, and the task runs every time:
Always run Task Scheduler as Administrator. If you don't have admin rights to do this, then you should even be here!
Don't create a Basic Task. Go straight to Create Task, and under your own admin account (doesn't have to be God Admin!).
When filling in the task wizard, don't provide a trigger UNTIL you've tested the task first. Also, make sure you've allowed the task to run whether you're logged in or not! That catches me sometimes.
Don't worry about Settings, for now. Accept the default
Save/OK
Close Task Scheduler
Restart it again, and again as Admin
Run the task you've created.
If all goes well, it ran! Do a CMD run of the EXE using #Wes's suggestion to be sure.
Now, place a Trigger of your choice
Change the Account to your proper task admin account, or a generic account with admin rights specifically created to run tasks. We call ours admin.tasks
Save everything and you should be ok from here.

Taskeng.exe multiple process

I've created two Batch scripts that I launch via the windows 7's Task Scheduler, and I've noticed that from times to times the execution of one of these scripts freezes. When this happens I get a Taskeng.exe window, and the only way to get rid of it is to kill the equivalent process.
And since I'm running those scripts on differents machines, whenever I log on in the morning, I find multiple Taskeng.exe windows from the previous executions.
Is there anyway to solve this problem ? Is there a way to kill those processes whenever their execution is incomplete ?
Thanks for reading.
Hicham

Jenkins task to switch on monitor if it's switched off

I use Jenkins to run our builds. What I want to do is to wakeup the monitor before build starts. This is what I have done so far.
Use nircmdc.exe (http://www.nirsoft.net/utils/nircmd.html) and prepare a batch file to turn on monitor. I have tested the script through command prompt and it works fine.
Then I add a build step in Jenkins to execute windows batch file before running the ANT script. Then I remote start the build (via URL). Console shows that the batch file is being executed. But the monitors doesn't wake up.
Then I included a target in ANT to execute the same batch file and tested running the ANT via CMD. This wakes up the monitor and continue with the build steps.
But, if I run this ant script from Jenkins, everything works fine except waking up the monitor.
Is this something to do with privileges ?
Has someone done something similar?
Don't think I've ever heard of a requirement to wake up the monitor, so probably no one has done anything like this.
However, your problem is probably due to Jenkins process running in a separate session from your machine's console. Have a look at my answer here: Open Excel on Jenkins CI, it explains how to get around the session issue.

Resources