Display Counter or any other thing till the time any command is running in script in Powershell - powershell

I have a script which has some commands that takes time to complete like 30 sec to 1 minute to get completed.
What I am trying to achieve is that till the time command is doing it works in the background we should get some counter or timer or anything getting displayed till the command is running.
When command gets completed, the counter gets stopped.
The user running the script should be aware that yes something is running.
For example like when we open any site and it takes time to load, we get the sand timer or something else as in the display.

Related

I have been playing with Forms, I run a Form with Start-Job with the option to stop it a 2nd job (Robocopy) I also have running

first, I have been playing with powershell for some time BUT I'm no programmer, so please keep that in mind
There are 2 way my script ends,
1 - I click on the Form's Stop Button All works fine, the Form closed and the second Job (robocopy) gets stopped all Good
2 - the Robocopy job ends then I need to close\stop the Form, the Stop-job\Remove-Job (with the -force option) work BUT there is a very Long delay as it stops the still "Running" Form job that is waiting for a key\button press
can anyone help
a stated the stop-job works but there is a very long delay, I have even been able to get the PID of the Form job and kill that (taskkill /f /pid) the Form window closes, but the get-job still show the Job state as "running" and Stop-job still have a very Long delay !!

Autohotkey restart script when time is up

I have an infinite loop script running. I want to run it during night without monitoring it (it gets stuck once in a while at something unavoidable).
So I need code to restart the script if 4 minutes are done. ( Script will finish within 3 minutes 100% ). Also, it should not restart before 3 minutes..
Thank you :)
Try the SetTimer command.
SetTimer, restartScript, -240000 ;run the timer just once after 240000 milliseconds
;main script here
;....
;return
restartScript:
Reload
return

How much of the code have been ran in Matlab?

When a heavy code is running in Matlab, is there any way to determine how much of the code have been ran till now? (How many percent)
You should pause the program, manually calculate how much is there still to go and decide whether to wait for it or give up.
https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
Pause a Running File
To pause the execution of a program while it is running, go to the Editor tab and click the Pause button. MATLAB pauses execution at the next executable line, and the Pause button changes to a Continue button. To continue execution, press the Continue button.
Pausing is useful if you want to check on the progress of a long running program to ensure that it is running as expected.
Note: Clicking the pause button can cause MATLAB to pause in a file outside your own program file. Pressing the Continue button resumes normal execution without changing the results of the file.
In the case you have an iterative process on where the time of each iteration will take approximately the same time (not always the case, but often this happens) then you can use this to know when will the code end:
for ii=1:niter
if (ii==1); tic; end
% your iteration
if (ii==1);
expected_time=toc*niter;
disp('Myalgorithm');
disp(['Expected duration : ',secs2hms(expected_time)]);
disp(['Exected finish time: ',datestr(datetime('now')+seconds(expected_time))]);
disp('');
end
end
Using sec2hms from FEX.
This code prints the following:
Myalgorithm
Expected duration : 41.0 secs
Exected finish time: 28-Mar-2017 10:58:57

Computer does not stay awake after scheduled task

I have a scheduled task that wakes up the computer to run a batch file. However the computer turns back off after some time. I have my computer set to (never sleep) so after waking up from the task it should stay on.
However after doing some reading I found out this was because the computer did not wake up from user input.
What I am looking for is a simple script (batch or vb file maybe) I can run via task scheduler that will simulate user input. Maybe hitting the space bar once or moving the mouse.
Running windows 8.1
I tried the following .vbs script without success
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.SendKeys("+{F10}")
You can try this application:
http://mousejiggler.codeplex.com/
It'll simulate mouse movement to keep your computer awake.
If you really want a script try this:
https://gallery.technet.microsoft.com/scriptcenter/Keep-Alive-Simulates-a-key-9b05f980
You can simulate the [F5] key to refresh windows every 2 minutes like this :
Option Explicit
Dim Ws
set Ws = createobject("Wscript.Shell")
Do
Ws.Sendkeys "{F5}"
Call Pause(2)'To sleep for 2 minutes
Loop
'***************************************
Sub Pause(min)
Wscript.Sleep(min*1000*60)
End sub
'***************************************

Windows Task Scheduler trigger on event, but only once a day

on Windows 7, how do I trigger on first occurance of an event each day to run a small batch file?
I'm trying to kick off a small batch script that runs only for a few seconds when I unlock my PC, but I only want it to run the first time I unlock my PC and never again until the I unlock my PC after 12AM of the next day. I can't tigger on specific time because the time at which I unlock my PC is random. I have been playing with task scheduler for days without success.
You could have the script set a state on first run, which keeps it from running again, for example by exiting immediately instead of doing anything when the state is set.
Then set up a task that triggers on log on to execute said script and another task that runs each day at 12AM to unset/remove the state set by the script. This should give you the effect you want.
A better solution, would be to have the script deactivate (f.e. via schtasks) the task triggered by logging on that called it and have the 12AM task restart the logon triggered task once each day.
I just faced the same problem, so here is my workaround without knowing to much scripting:
I created 4 .bat-files containing basically the following.
start application, afterwards replace bat-file1 with bat-file2
do nothing
replace bat-file1 with bat-file4
start application, afterwards replace bat-file1 with bat-file2
Now I created to scheduled tasks:
The first one runs every day at 12am and runs batch-file 3. Hence, it replaces bat-file1 with bat-file4.
The second one runs after every unlocking of the computer and runs batch-file1.
As you can see in total it does exactly what you want, although it might be a little bit complicated...
On your first unlock it starts your desired script and replaces itself with a dummyfile (the batch file only contains the word exit). After every following unlocking nothing but a hardly noticable cmd popup happens.
At 12am the dummyfile is replaced by the initial batch-file again, to provide your task in the next morning.