{"id":229,"date":"2018-06-29T00:09:10","date_gmt":"2018-06-29T08:09:10","guid":{"rendered":"http:\/\/gmrgames.com\/blog\/?p=229"},"modified":"2022-02-15T03:39:54","modified_gmt":"2022-02-15T11:39:54","slug":"how-to-only-run-a-program-when-your-laptop-is-plugged-in","status":"publish","type":"post","link":"https:\/\/rose.dev\/blog\/2018\/06\/29\/how-to-only-run-a-program-when-your-laptop-is-plugged-in\/","title":{"rendered":"How to only run a program when your laptop is plugged in"},"content":{"rendered":"<p>Here&#8217;s a tricky one. How do you run a program or exe ONLY when your Windows laptop is plugged in? Additionally, you&#8217;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 <a href=\"https:\/\/www.rainmeter.net\/\">Rainmeter<\/a> on my laptop when it&#8217;s plugged in.<\/p>\n<p>The answer is to use the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/taskschd\/about-the-task-scheduler\">Task Scheduler<\/a>.<\/p>\n<p>Here&#8217;s what you&#8217;ll need to do.<\/p>\n<ol>\n<li>Open Task Scheduler.<\/li>\n<li>Click &#8220;Create Task&#8230;&#8221; under <em>Task Scheduler Library<\/em>.<\/li>\n<li>Name your task and give it a description.<\/li>\n<li>If your application needs admin privileges, make sure to check the box at the bottom, &#8220;Run with highest privileges&#8221;<\/li>\n<li>Open the <em>Triggers<\/em> tab at the top. Click &#8220;New&#8230;&#8221; at the bottom.<\/li>\n<li>Change the <em>Begin the<\/em> <em>task<\/em> value to &#8220;On an event&#8221;.<\/li>\n<li>Under &#8220;Settings&#8221;, change the radio button selection from &#8220;Basic&#8221; -&gt; &#8220;Custom&#8221;.<\/li>\n<li>Click &#8220;New Event Filter&#8230;&#8221;.<\/li>\n<li>Disregard the &#8220;Filter&#8221; tab, and instead change the tab to &#8220;XML&#8221;.<\/li>\n<li>Check the box at the bottom that states &#8220;Edit query manually&#8221;.<\/li>\n<li>Paste this XML in:<\/li>\n<\/ol>\n<pre><code>&lt;QueryList&gt;\n  &lt;Query Id=\"0\" Path=\"System\"&gt;\n    &lt;Select Path=\"System\"&gt;*[EventData[Data[@Name='AcOnline']='true']]&lt;\/Select&gt;\n  &lt;\/Query&gt;\n&lt;\/QueryList&gt;<\/code><\/pre>\n<p>Click &#8220;OK&#8221;, and then &#8220;OK&#8221; again.<\/p>\n<p>Once back on the main page, you may now configure your &#8220;Actions&#8221; tab to launch your program of choice.<\/p>\n<p>Once finished, proceed to the settings tab and make sure you have these settings:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/keLPFBp.png\" \/><\/p>\n<p>Congratulations! You can now test it by plugging in your laptop and watching your program launch itself. Unplugging it should quit it instantly.<\/p>\n<hr>\r\nIt helps me if you share this post\r\n<br\/>\r\n<br\/>\r\nPublished 2018-06-29 00:09:10 ","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a tricky one. How do you run a program or exe ONLY when your Windows laptop is plugged in? Additionally, you&#8217;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&#8217;s &hellip; <a href=\"https:\/\/rose.dev\/blog\/2018\/06\/29\/how-to-only-run-a-program-when-your-laptop-is-plugged-in\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to only run a program when your laptop is plugged in<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[1],"tags":[959,964,955,965,960,956,961,954,957,953,958,951,952,963,962],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ac-adapter","tag-battery","tag-charging","tag-check","tag-connected","tag-exe","tag-execute","tag-in","tag-laptop","tag-plugged","tag-power","tag-program","tag-run","tag-scheduler","tag-task"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":1,"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":1268,"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions\/1268"}],"wp:attachment":[{"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rose.dev\/blog\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}