{"id":66123,"date":"2006-11-02T22:09:00","date_gmt":"2006-11-02T22:09:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/11\/02\/how-can-i-enable-system-restore-using-a-script\/"},"modified":"2006-11-02T22:09:00","modified_gmt":"2006-11-02T22:09:00","slug":"how-can-i-enable-system-restore-using-a-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-enable-system-restore-using-a-script\/","title":{"rendered":"How Can I Enable System Restore Using a Script?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p>Hey, Scripting Guy! How can I enable Windows XP\u2019s System Restore using a script?<\/p>\n<p>&#8212; RL<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/a><\/p>\n<p>Hey, RL. Thanks for the question; the Scripting Guy who writes this column is running <i>way<\/i> late today, the clock is ticking, and he was desperately in need of a question a he could answer without having to use a lot of code. A question about enabling System Restore is just what the doctor ordered, or at least it would be if the doctor happened to be writing a daily scripting column. To tell you the truth, we don\u2019t really know whether doctors write daily scripting columns or not. We\u2019re guessing that most do, but that\u2019s just a guess.<\/p>\n<p>But here\u2019s one thing we <i>do<\/i> know, for sure: contrary to popular belief, the international distress code SOS is <i>not <\/i>short for <i>Save Our Ship<\/i>. Instead, the letters S-O-S were chosen because they represent simple, all-but-impossible to misinterpret Morse code: three dots, three dashes, three dots. The letters don\u2019t actually stand for anything at all. <\/p>\n<p>Pardon? You\u2019re suggesting that, if we really <i>are<\/i> way behind schedule (which we are), it might be better for us to talk about scripting rather than talk about some arcane trivia no one else cares about? You know, that\u2019s good advice, and we\u2019ll do it \u2026 assuming we ever stumble upon some arcane trivia that no one else cares about. But we hardly think the origin of SOS falls into that category.<\/p>\n<p>On the other hand, now that we\u2019ve pretty much exhausted our knowledge both of the SOS distress call and of Morse code, well, about all we <i>can<\/i> do is talk about the script. With that in mind, here\u2019s a script that enables System Restore on a computer running Windows XP:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\default\")\nSet objItem = objWMIService.Get(\"SystemRestore\")\nerrResults = objItem.Enable(\"\")\n<\/pre>\n<p>You can see why, on a busy day, we chose to answer this particular question: just a few lines of code and we\u2019ve got ourselves a column. The script itself starts out in typical fashion, connecting to the WMI service on the local computer. (Although, like all good WMI scripts, this one will also work against remote computers; just assign the name of that computer to the variable strComputer.) One thing to watch out for, however: unlike most WMI scripts this one doesn\u2019t connect to the root\\cimv2 namespace; instead, it connects to the <b>root\\default<\/b> namespace. Why? That\u2019s easy: that\u2019s where all the System Restore WMI classes reside.<\/p>\n<p>After making the connection we use the <b>Get<\/b> method to bind to the <b>SystemRestore<\/b> class; that\u2019s what we do here:<\/p>\n<pre class=\"codeSample\">Set objItem = objWMIService.Get(\"SystemRestore\")\n<\/pre>\n<p>At that point we can enable System Restore on all drives by simply calling the <b>Enable<\/b> method and passing an empty string (\u201c\u201d) as the sole parameter.<\/p>\n<p>Anyway, thanks again for the question, RL, we have to \u2013 well, yes, like we said, that does enable System Restore on all drives. Could we enable System Restore on a particular drive? Well, like we said we\u2019re running kind of late here \u2013 oh, what the heck. Here\u2019s a script that enables System Restore only for drive D on the local computer:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\default\")\nSet objItem = objWMIService.Get(\"SystemRestore\")\nerrResults = objItem.Enable(\"D:\\\")\n<\/pre>\n<p>Yes, it\u2019s remarkably similar to the first script we showed you; in fact, the only difference lies with the parameter passed to the Enable method. To enable System Restore on all drives we pass an empty string to this method; to enable System Restore only on drive D we pass the Enable method this parameter: <b>D:\\<\/b>. In other words, we pass the drive letter (<b>D<\/b>) followed by <b>:\\<\/b>. To enable System Restore on drive E and drive E only we\u2019d use this line of code:<\/p>\n<pre class=\"codeSample\">errResults = objItem.Enable(\"E:\\\")\n<\/pre>\n<p>Etc. <\/p>\n<p>We really have to go now, so \u2013 what\u2019s that? What if you later want to <i>disable<\/i> System Restore on a computer? You know, we really don\u2019t have time to \u2026. Look, we\u2019ll make you a deal: one more script and then we have to go. OK? OK. Here\u2019s a script that disables System Restore for all the drives on a computer:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\default\")\nSet objItem = objWMIService.Get(\"SystemRestore\")\nerrResults = objItem.Disable(\"\")\n<\/pre>\n<p>Again, very similar to the first script we showed you; in fact, the only difference is that this time we call the <b>Disable<\/b> method instead of the Enable method. And, yes, as a matter of fact you <i>can<\/i> disable System Restore for a specific drive. Tired of running System Restore on drive D? Then don\u2019t:<\/p>\n<pre class=\"codeSample\">strComputer = \".\"\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\default\")\nSet objItem = objWMIService.Get(\"SystemRestore\")\nerrResults = objItem.Disable(\"D:\\\")\n<\/pre>\n<p>That\u2019s all we have time for; we absolutely <i>have<\/i> to go. Although we probably should add that, prior to SOS, the international distress call was <b>CQD<\/b>. The letters CQ represented a general message that was sent to all stations, with the letter D indicating \u201cdistress.\u201d In other words, CQD meant \u201cAttention all stations, we have a distress call.\u201d In fact, the ill-fated Titanic originally sent out several CQD calls before trying SOS. As it turns out \u2013 wait a second, where are you going? What do you mean you\u2019re too busy to stay and listen to our story? Come on, surely you can make time for \u2013 this will only take a minute \u2013 are you sure you can\u2019t stay just \u2013 oh. Well, OK. We can always save this story for a future column.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I enable Windows XP\u2019s System Restore using a script? &#8212; RL Hey, RL. Thanks for the question; the Scripting Guy who writes this column is running way late today, the clock is ticking, and he was desperately in need of a question a he could answer without having to use [&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":[16,3,723,5],"class_list":["post-66123","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-scripting-guy","tag-system-restore","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I enable Windows XP\u2019s System Restore using a script? &#8212; RL Hey, RL. Thanks for the question; the Scripting Guy who writes this column is running way late today, the clock is ticking, and he was desperately in need of a question a he could answer without having to use [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66123","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=66123"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66123\/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=66123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}