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.
Related
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.
I have a job in autosys and I need to update it to remove the starting time completely.
Currently the start time is set to run at 10pm every night.
update_job: myjobname
start_times:
Do I leave the start_times blank as above or do I change it to start_times: " "
Any help would be greatly appreciated.
Yes, you have to keep it as blank. However, along with this you have to remove the days_of_week or run_calendar as applicable:
update_job: myjobname
start_times:
days_of_week:
If you are looking to remove this from schedule, another way is to just update the boolean value of date_condition
update_job: myjobname
date_conditions: n
here "n" would mean not to follow the timings. It can be mentioned as 0 or 1. The user has to force start the job on need basis.
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
I have started running a script on MATLAB that takes days to finish. Usually, if I changed my mind and I don't want wait for it to finish and I get content with the intermediate results, I highlight the command window and press Ctrl-C to break the code.
Now, I have run MATLAB. But its desktop got kinda stuck in the background. When I try to restore the desktop from the toolbar, it does not restore. But I know from the task manager that the process is running and is consuming Memory and CPU performance. So, I am kinda stuck. I don't want to kill the process because I need the intermediate values in the workspace, and I can't open the desktop to break the code using ctrl-c.
Is there any solution? For example, is there any command that can be used in the command prompt to act as ctrl-c for MATLAB?
I am using MATLAB R2012b and Windows 8.
Quick try to fix the recent Problem:
Try ty set a higher priority to matlab.exe in the Task Manager. (Right click -> Priority -> Higher than normal). Then see if you can get the window to front.
Some approaches to avoid this problem in future:
Try to optimize your code. For starters look at: http://de.mathworks.com/help/matlab/matlab_prog/vectorization.html
Use Matlab compiler for faster execution: http://de.mathworks.com/products/compiler/
Include some drawnow commands at stratetic positions in the code. This allows matlab to process the Event Queue and capture ctr-C commands.
Save intermediate results to output files. For example you could write an output file all 30 min with your intermediate results. Easyiest way would be just save(filename). Then a .matfile with all your workspace variables is generated. You can than kill the process in the task manager, without loosing too much results.
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
'***************************************