Close running app when my laptop goes to sleep in Windows 7 (close the lid or sleep button is pressed) - windows-7

I have a program (program.exe) which I want to be closed when my laptop goes to sleep either if the sleep button was pressed, the lid was closed or some time has passed and entered automatically in sleep mode.
I suspect is something from the Task Scheduler but I don't know how to find event "When laptop goes to sleep" and then to close program.exe
I know that maybe I can do a Python script but I feel Task Scheduler it's the easiest way and maybe someone else, like me, needs to fix the same challenge.
Thanks!

After some digging, I found the solution I will post it here maybe it helps someone at some moment.
Open Task Scheduler
Create Task
Give it a name (Close_program_on_sleep)
Check Run whether user is logged on or not
Select Configure for Windows 7
Go on Triggers tab and then select New
Select from Begin the task: On an event
Select Log = System Source = Kernel-Power Event ID = 42. Click ok
On Actions tab click new and then New> Start a program
On the Program/Script add taskkill /f /im "your_program_to_be_closed.exe"
Ok
Enjoy :)!

Related

How do I make a custom-created windows schedule task not run in background?

I've made a scheduled task that repeats itself each 4 hours. The task is that it starts a program that automatically will shutdown in 4 hours from start. But when I have windows task scheduler set to open the software each 4 hours, it just starts the process, not opening an actual window. How can I solve this?
The user is set to the useraccount I'm logged in to, not system.
Answer was basic: I had selected "Run even if user is logged off", meaning it'd run it all in another session or something like that. So I tried selecting "Run only if user is logged in" and it works like a charm! :)

How to reliably reboot a windows PC with command line?

I have to reboot 5 windows PC every week all located in remote location, I remote desktop to the machine and use command "shutdown -r -t 0" to reboot, but one of the PC won't come up until someone go to it and power down and up again, should I change any setting? its all Win7 PCs. thanks.
You can try something different to do all of this automatically for you.
Click "Start"
Type "Task Scheduler"
Click "Create Task"
Now, you can create a new task that will run every day.
Here are a few important tips for setup:
In the General tab, make sure you select the option to run the event whether or not a user is logged in.
In the Triggers tab, add a new trigger and select Daily and the time for when the event should occur.
In the actions tab, create a new action with a script of something like the following
shutdown -s -t 60 -c "System now shutting down. Save all work."
In the conditions tab, change the settings so that the event will not occur while the machine is in use and delay the event until the system has been inactive for a specified amount of time.
Just on a note, this site is for programming, not IT support. Although this contains batch, this is more about IT support.
Type shutdown /? from a command prompt
also you can create new task to restart you pc by start powershell and Type shutdown -s -t 60 -c
Good luck

Can you configure Qt Creator to kill the running application before building or running?

I'm developing a QApplication and I find that I often forget to close my application before rebuilding and re-running it. This becomes a problem when I accidentally look at an instance of my application built 10 minutes ago and expect to see code changes from 30 seconds ago.
It is also annoying because I have to move my hand all the way over to the mouse, move the mouse all the way over to the running application, and close it every time I want to rebuild and I am lazy and I don't want to do that.
Is it possible to configure Qt Creator to close my QApplication when I start building or running it again?
There is an option to do that in Qt Creator:
Open the Preferences => Build & Run => General
Change “Stop application before building” from “None” to “Same Project”
To whomever might stumble here later, an easier way to o this is to put a "killall" command (as suggested by tangbongbong) is the first build step under Projects(ctrl+5) -> Build and Run
In the screenshot below my executable name was "Tutano" and I added the -9 option to ensure it would be killed.
Screenshot
- sorry, I'm new here so can't post an image directly
Try to add the following Custom Process Step at the top of the Build Steps
I am on Windows so the killall does not work.
But I figured this out (enter the values in the same form that Julien has posted as a screenshot):
Command: taskkill
Arguments: /FI "STATUS eq Running" /IM APPNAME.exe /F
You need to replace APPNAME with your application's name, of course.
The /FI "STATUS eq Running" is a filter that enables qmake to proceed after this pre-build-step, even if the application is not yet running (else it would not find the process to kill and then exit). Without the /F the application won't get closed, at least for me.
However, if your application has a icon in the trayarea, the icon won't disappear. The icon gets removed when you move the mouse over it.
Yes.
One way is to create a very simple script that kills your existing running process and starts a new one. If your program executable is FooBarProgram then go to the build directory that Qt has created and create this file FooBarProgramLauncher
#!/bin/bash
killall FooBarProgram
./FooBarProgram
Now change the Qt project configuration to run your launcher instead running your program directly:
Open the project in Qt Creator
Select "Projects" from the pane on the left
Select the "Build & Run" tab if not already selected
Select the "Run" subtab
Under the "Run" heading, click the "Add" button, select "Custom Executable"
On the "Command" line, click the "Browse" button and select FooBarProgramLauncher
Now whenever you tell Qt to run your program it will run FooBarProgramLauncher instead which in turn will kill any running instances of FooBarProgram and then run the newly compiled executable.

Schedule to run a program and click some radiobutton and button in sequence

Is it possible to automate a program in windows and run a sequential click of each control and buttton. for example click some radiobutton to configure some setting and press enter.
For an example, Is it possible if i run this cauculator program once a day click 1+1 then click equal and close this program after it finished execution or at a certain amount of time for example 1 15 minute
Add More information : i have a program that my boss want to run this once a day. I have to click the same radio button setting everyday and press enter. i have no source code of it i am just an end user. i am looking for a way to automate this
Not sure what you really intend, but AutoHotkey might be your weapon of choice for the automation part. The scheduling can also be done in AutoHotKey or with the Windows inbuilt task scheduler.

Task Scheduler - Show me a message when I lock my computer

Here's what I need to happen:
When I leave the office for the day, I lock my computer. We're supposed to fill out our timecards before leaving. I always forget to do it. I want a message to be displayed when I attempt to lock my computer asking me if I've filled out my timecard.
Here's what I've done, and why it doesn't work:
I created a task under Task Scheduler with action = "Display a message" and trigger = "On workstation lock". The problem with this is the task doesn't run until the workstation is literally locked and I don't see the message until I log back in again, which is pointless.
How can I do this so immediately after I press Ctrl-Alt-Del, but before my computer actually locks the message is displayed?
Any help would be appreciated. Bonus points awarded for the following:
1) Display the message only if after say 3:00pm, as I lock my computer multiple times a day and I would get the message every time. The 3:00pm constraint would assume I'm leaving for the day and therefore, it should ask me if I've filled it out.
2) At the end of the message, display "Would you like to visit the timecard site?" and display 2 buttons, Yes and No. If I click yes, the locking of the workstation is cancelled and the timecard site opens up in my browser. If no is clicked, the workstation goes on to be locked.
Thanks.
You could pop your message up by calling MessageBox() with the MB_SERVICE_NOTIFICATION flag. That will cause the message box to be popped up on the console even if the logon screen is showing...
I doubt that this is possible. When you press CTRL+ALT+DEL Windows handles that key press and you can't get a look in.
What you could do would be to put a shortcut on you desktop that locked the computer, but only after having shown the message you so desire. I have a Lock Workstation shortcut on my desktop which is implemented with the following target:
C:\Windows\System32\rundll32.exe User32.dll,LockWorkStation
You could quite easily write your own script, or maybe even a small app. If the latter then you simply need to call the LockWorkStation function that is exported from user32.dll.
change the action to a program, run this program
msg username message
ie: msg patrick Please remember to do this.

Resources