How to only run a program when your laptop is plugged in

Here’s a tricky one. How do you run a program or exe ONLY when your Windows laptop is plugged in? Additionally, you’d want it to automatically exit when your laptop was unplugged and you were using battery power. I recently stumbled across this problem when I wanted to run Rainmeter on my laptop when it’s plugged in.

The answer is to use the Task Scheduler.

Here’s what you’ll need to do.

  1. Open Task Scheduler.
  2. Click “Create Task…” under Task Scheduler Library.
  3. Name your task and give it a description.
  4. If your application needs admin privileges, make sure to check the box at the bottom, “Run with highest privileges”
  5. Open the Triggers tab at the top. Click “New…” at the bottom.
  6. Change the Begin the task value to “On an event”.
  7. Under “Settings”, change the radio button selection from “Basic” -> “Custom”.
  8. Click “New Event Filter…”.
  9. Disregard the “Filter” tab, and instead change the tab to “XML”.
  10. Check the box at the bottom that states “Edit query manually”.
  11. Paste this XML in:
<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">*[EventData[Data[@Name='AcOnline']='true']]</Select>
  </Query>
</QueryList>

Click “OK”, and then “OK” again.

Once back on the main page, you may now configure your “Actions” tab to launch your program of choice.

Once finished, proceed to the settings tab and make sure you have these settings:

Congratulations! You can now test it by plugging in your laptop and watching your program launch itself. Unplugging it should quit it instantly.


It helps me if you share this post

Published 2018-06-29 00:09:10

Searchifier is officially released!

About time, too! 😀 Here’s the information:

Microsoft enforces the policy that searching from Cortana opens the search in Bing and on Microsoft Edge. Searchifier enables you to search with whatever browser and search engine you want, seamlessly. It’s under a five second install, and allows you freedom in using a great feature of Windows 10. Lightweight (under a megabyte), unintrusive (doesn’t run in the background), and fast, it’s a necessary download for anyone looking to augment and enhance their Windows experience.

LINKS:

SEARCHIFIER WEBSITE

It’s, of course, DRM and virus free.

Later edit: Microsoft broke Searchifier. Read this.


It helps me if you share this post

Published 2018-06-18 01:18:14

So what happened was…

Okay, so this is an update of what happened with the whole “I accidentally wiped my entire hard drive”.

The Non-Techie Version

If you don’t know much about computers, read this.

I accidentally told the program that the folder it should delete was my main hard drive when it was uninstalling itself. Not much else to it.

The “I know that arrays start at 0” Version

  1. The uninstall string I set for the program in the registry passes the argument “uninstall” to my program.
  2. My program takes the argument and knows it’s about to uninstall itself. It then asks for admin access.
  3. Once achieving admin access, it then copies itself to a temporary directory. This is the TEMP path in Windows.
  4. The original program starts the copy of itself with two arguments: “uninstall”, and the path of the original. In this case, it was “C:/Program Files/Searchifier/searchifier.exe”.
  5. The program knows since it got passed an argument with a path to delete it and uninstall registry keys and the like.
  6. However, the path I passed was not verbatim. Therefore, the arguments passed looked like this: uninstall C:/Program Files/Searchifier/searchifier.exe
  7. This caused a massive problem. Since there is a space between ‘Program’ and ‘Files’, Windows feeds that to my program as THREE separate arguments, not two.
  8. My program receives three arguments:
    1. uninstall
    2. C:/Program
    3. Files/Searchifier/searchifier.exe
  9. The program only cares about the first two. It knows it’s going to uninstall itself, so first it tries to delete the file at the location “C:/Program”. This fails, but the program continues on.
  10. It next attempts to delete the directory at which the program resides. To do this, it gets the parent folder of the path it just tried to delete. This is… the C: drive.
  11. It then calls a recursive delete function on “C:”.
  12. I then spend the next 6 days in deep depression trying to recover all my files. 🙂

With that, SEARCHIFIER is now out! I’ll make another post about this later as well, but it’s now officially [HERE].


It helps me if you share this post

Published 2018-06-07 19:47:12

I never thought this would be me, but…

I remember a while ago (probably a year or two), my sister brought her computer over to my family’s house and thrust it at me. “It’s not working.” Was her wholly unhelpful description of the problem. Being used to this sort of treatment, I pressed the power button to begin troubleshooting. Almost instantly, the screen came to life and displayed nothing else but a missing drive icon. “Looks like a failed hard drive.” Was my response. “You backed up, right?” Of course she hadn’t. Luckily, by analyzing the hard drive from an external source, we were able to recover all of her important information. This was a lesson to me, always back up. Your computer could fail when you least expect it.

Or at least, I thought I learned a lesson. It was eleven o’clock the other night when I was testing out the uninstall function of my new program. It was alllllmost ready for release, 99% done. Just had to get the uninstallation feature correct. Everything was working perfectly. And then I did what no developer should ever do (apparently). Ran it on my main computer/harddrive. As a developer/coder, all sorts of crap can always go wrong, so you should always have a some layer of protection between programs and your main working computer… or a backup. Going with that, you should never test on production (the main server you use for anything, company-wise or not). I ran the program, and everything looked great. Now time to test the uninstallation function. I went to the apps list on Windows, and confidently clicked “Uninstall”. My app, as planned, requested admin permissions. I clicked “Yes” without a second thought. And waited.

Nothing happened. So I clicked uninstall again. Same result. That’s odd. I thought to myself. I’ll check the code. I opened up File Explorer to see that half the folders in my C: drive were missing. …What? Was my first thought. I backed out to “My Computer” view to find that I had an extra 500 GB of space available to me that had been freshly freed up not 10 seconds ago. My hand shakily moused over the Recycle Bin, praying that the files would be there. But no. My code bypassed the Recycle Bin. I still have no idea what happened, but the deletion of my files was so severe that as I was powering down the computer to try and save as much data for data recovery later, Windows was throwing errors about being unable to find critical system files and .dlls.

My guess as to what happened? Actually not sure. You can bet I’m going to post an update when I figure it out though. The data recovery program I’m using says that it’s gonna take 10 more hours at least for just my Documents folder, though. Lesson learned. Always keep backups.


It helps me if you share this post

Published 2018-05-31 23:25:44

Update

I’ve released my old AutoResequencer source [here]. It’s a tool that will help you sort large quantities of files. Most useful if you’re a game developer, or have lots of pictures named similarly.

That’s all for now!


It helps me if you share this post

Published 2018-04-29 18:27:00