{"id":64113,"date":"2007-08-31T01:46:00","date_gmt":"2007-08-31T01:46:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/08\/31\/how-can-i-execute-a-scheduled-task-in-windows-vista\/"},"modified":"2007-08-31T01:46:00","modified_gmt":"2007-08-31T01:46:00","slug":"how-can-i-execute-a-scheduled-task-in-windows-vista","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-execute-a-scheduled-task-in-windows-vista\/","title":{"rendered":"How Can I Execute a Scheduled Task in Windows Vista?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! I understand that, in Windows Vista, I can write a script that will cause a scheduled task to immediately execute. How do I do that?<BR><BR>&#8212; KW<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, KW. Before we answer today\u2019s question, we\u2019d like to take a moment to say a few things in memory of our colleague, Scripting Guy Dean Tsaltas. Not that Dean has <I>died<\/I> or anything; physically he\u2019s in great shape. (Well, OK: physically he\u2019s in as good a shape as he ever is.) No, as it turns out, Dean has suffered a fate far worse than death: he and his family are moving back to Halifax, Nova Scotia.<\/P>\n<TABLE class=\"dataTable\" id=\"E6C\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Sample Nova Scotian humor.<\/B> Did you hear about the war between Newfoundland and Nova Scotia? The Newfies were lobbing hand grenades; the Nova Scotians were pulling the pins and throwing them back.<\/P>\n<P>OK, well, we assume this joke is like curling: you probably have to be Canadian to truly appreciate it.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Now, for those of you who worry about things like this, don\u2019t worry: Dean was, is, and always will be a Scripting Guy. In addition, Dean is still working for Microsoft, and he\u2019s working on the <A href=\"http:\/\/msdn2.microsoft.com\/library\/aa394582.aspx\" target=\"_blank\"><B>WMI SDK<\/B><\/A>; the only difference is that he\u2019ll be doing this work in Halifax, where you\u2019re much more likely to find a slice of Rappie Pie than you are here in Redmond. <\/P>\n<TABLE class=\"dataTable\" id=\"ETD\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Nova Scotian recipe. <\/B>One traditional recipe for Rappie Pie includes, among other things, the following ingredients: 2 pounds of fatty pork; \u00bc pound of pork fat; \u00bc pound of fried salt port. And if you get tired of Rappie Pie (as if!), well, in that case you can always run down to the grocery store and get a box of salted codfish. As the name implies, salted codfish is nothing more than codfish that has been immersed in salt and then dried in the sun. Do those Nova Scotians know how to live or what?<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>At any rate, we Scripting Guys would like to take a moment to pay tribute to Dean and all the many wonderful things he\u2019s done for the Script Center and for the scripting world at large. Unfortunately, however, while we\u2019d <I>like<\/I> to take a moment to pay tribute to Dean and all the many wonderful things he\u2019s done for the Script Center and the scripting world at large, we couldn\u2019t actually think of anything he\u2019s done, wonderful or otherwise. But, then again, he only worked here for six years.<\/P>\n<P>Oh, wait, we just thought of something: Dean <I>did<\/I> get us all in trouble when he said the word \u201cpee\u201d during one of our <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/webcasts\/archive.mspx#EQF\"><B>Scripting Week 1 webcasts<\/B><\/A>. And he <I>did<\/I> write the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/tools\/scripto2.mspx\"><B>Scriptomatic<\/B><\/A>, the tool that, more than anything else, helped bring WMI into the world of system administration. And if that wasn\u2019t enough, you could also count on Dean to go along whenever it was time for lunch; in fact, Dean would happily take two or three lunches a day if necessary.<\/P>\n<P>And once Dean is gone, how will the rest of ever know what\u2019s going on in the world of Ultimate Fighting?<\/P>\n<P>In other words, this is a sad day for the Scripting Guys. But things will work out: after all, Dean might be gone, but he won\u2019t be forgotten. Instead, he\u2019ll remain foremost in our minds, the very same way that \u2026 um \u2026 that the \u2026 uh \u2026 <I>other<\/I> Scripting Guy, the one who <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/feb07\/hey0202.mspx\"><B>became a PM or something<\/B><\/A>, has remained foremost in our minds.<\/P>\n<P>Besides, there\u2019s nothing to prevent all of us from going to Halifax to visit Dean, is there?<\/P>\n<TABLE class=\"dataTable\" id=\"EEF\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Nova Scotian Weather Report<\/B>. In January, 1993 the temperature at the Halifax Airport reached a low of -28.5 degrees Celsius (-19.3 degress Fahrenheit). On February 19, 2004, the airport was inundated with 66 centimeters (26 inches) of snow.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Of course, sad day or not, duty calls. With that in mind, here\u2019s a little farewell gift to Dean from his fellow Scripting Guys; a script that, under Windows Vista, can immediately execute a scheduled task:<\/P><PRE class=\"codeSample\">Set objTaskService = CreateObject(&#8220;Schedule.Service&#8221;)\nobjTaskService.Connect<\/p>\n<p>Set objRootFolder = objTaskService.GetFolder(&#8220;\\&#8221;)\nSet objTask = objRootFolder.GetTask(&#8220;Test Task&#8221;)<\/p>\n<p>objTask.Run vbNull\n<\/PRE>\n<P>If this looks like a pretty simple little script, well, there\u2019s a good reason for that: it <I>is<\/I> a pretty simple little script. As you can see, we start out by creating an instance of the <B>Schedule.Service<\/B> object, and then call the <B>Connect <\/B>method; that connects us to the Task Scheduler service on the local computer. Can we perform this same task on a <I>remote<\/I> computer, say, a computer named atl-fs-01? You bet we can; all we have to do is pass the name of that computer to the Connect method, like so:<\/P><PRE class=\"codeSample\">objTaskService.Connect(&#8220;atl-fs-01&#8221;)\n<\/PRE>\n<P>After connecting to the Task Scheduler service, we use the <B>GetFolder<\/B> method to bind to the Task Scheduler\u2019s root folder:<\/P><PRE class=\"codeSample\">Set objRootFolder = objTaskService.GetFolder(&#8220;\\&#8221;)\n<\/PRE>\n<P>What\u2019s that? What if your task is in a <I>subfolder<\/I> of the root folder; you know, a folder with a name like Admin Tasks? No problem; just specify the complete path to the folder, like so:<\/P><PRE class=\"codeSample\">Set objRootFolder = objTaskService.GetFolder(&#8220;\\Admin Tasks&#8221;)\n<\/PRE>\n<P>Once we connect to the proper folder we can then call the <B>GetTask<\/B> method to create an object reference to the desired task; to do this, we simply pass GetTask the name of the task we want to run:<\/P><PRE class=\"codeSample\">Set objTask = objRootFolder.GetTask(&#8220;Test Task&#8221;)\n<\/PRE>\n<P>And then to run the task we just have to call the <B>Run<\/B> method, passing the VBScript constant vbNull as a way to indicate that we want to run the task without any special parameters:<\/P><PRE class=\"codeSample\">objTask.Run vbNull\n<\/PRE>\n<P>Just like that, the scheduled task Test Task will run.<\/P>\n<TABLE class=\"dataTable\" id=\"EZG\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. You\u2019re absolutely right: the Task Scheduler in Windows Vista is way cooler \u2013 and way more scriptable \u2013 than the Task Scheduler in other versions of Windows. For a quick introduction to writing scripts that interact with the Windows Vista Task Scheduler take a peek at our article <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/vista\/tasks1.mspx\"><B>Task Scheduler: Part 1<\/B><\/A>.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>And just like that, we\u2019re done for today. We\u2019ll be back tomorrow, although with a heavy heart: tomorrow is Dean\u2019s last day. But to tell you the truth, between Rappie Pie, salted codfish, and the Duck Trolling Retriever (the official dog of the province of Nova Scotia), it\u2019s amazing to us that <I>everyone<\/I> hasn\u2019t decided to move to Nova Scotia. Good luck, Dean, and remember: although you might be in Halifax, there will always be a place for you here in the Script Center.<\/P>\n<P>Well, as long as you don\u2019t use the word \u201cpee.\u201d We\u2019d just as soon not go through all <I>that<\/I> again.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I understand that, in Windows Vista, I can write a script that will cause a scheduled task to immediately execute. How do I do that?&#8212; KW Hey, KW. Before we answer today\u2019s question, we\u2019d like to take a moment to say a few things in memory of our colleague, Scripting Guy Dean [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,32,3,5,725],"class_list":["post-64113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-scheduled-tasks","tag-scripting-guy","tag-vbscript","tag-windows-vista"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I understand that, in Windows Vista, I can write a script that will cause a scheduled task to immediately execute. How do I do that?&#8212; KW Hey, KW. Before we answer today\u2019s question, we\u2019d like to take a moment to say a few things in memory of our colleague, Scripting Guy Dean [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=64113"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64113\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=64113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=64113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=64113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}