{"id":55873,"date":"2008-04-02T00:34:00","date_gmt":"2008-04-02T00:34:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2008\/04\/02\/hey-scripting-guy-how-can-i-open-an-alternate-home-page-if-the-default-home-page-isnt-available\/"},"modified":"2008-04-02T00:34:00","modified_gmt":"2008-04-02T00:34:00","slug":"hey-scripting-guy-how-can-i-open-an-alternate-home-page-if-the-default-home-page-isnt-available","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-open-an-alternate-home-page-if-the-default-home-page-isnt-available\/","title":{"rendered":"Hey, Scripting Guy! How Can I Open an Alternate Home Page If the Default Home Page Isn\u2019t Available?"},"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! In our company we hardcode everyone\u2019s computer to use our intranet site as their Internet Explorer home page. All our users use laptop computers, however, and when they take the machines home with them and try to surf the Web they always start off with a Page Not Found error; that\u2019s because they can\u2019t reach our intranet from home. Is there any way to script things so that, if the intranet isn\u2019t available, they open an alternate home page instead?<\/p>\n<p>&#8212; JF<\/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, JF. You know, today is April 1<sup>st<\/sup>; that is, today is \u201cApril Fool\u2019s Day\u201d in the US and many other countries around the world. April Fool\u2019s Day is the day you\u2019re supposed to play pranks on people, and media titans such as <i>Sports Illustrated<\/i>, the BBC, and the <i>New York Times<\/i> have all taken their shot at pulling elaborate hoaxes. (Take a peek at <a href=\"http:\/\/www.museumofhoaxes.com\/hoax\/aprilfool\/P0\/\" target=\"_blank\"><b>this Web site<\/b><\/a> for a list of the 100 greatest hoaxes of all time. We\u2019re not sure if the 1957 Swiss spaghetti harvest is truly the <i>greatest<\/i> hoax of all time, but it <i>is<\/i> pretty good.) <\/p>\n<p>The Scripting Guy who writes this column has always wanted to do an April Fool\u2019s edition of the Script Center, but has never followed through on it. He\u2019s not sure what he would do exactly, but probably the Script Center would include a number of articles along the lines of announcing that Microsoft has bought McDonald\u2019s and will soon be coming out with the Vista QuarterPounder with cheese. (\u201cSomeone is trying to take a bite out of your hamburger. Do you want to allow this?\u201d) But, like we said, he\u2019s never followed up on that.<\/p>\n<table id=\"ESD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. Why not? Well, when most of you hear the word \u201cTechNet\u201d you probably think, \u201cOh, right, TechNet; what a fun-loving, devil-may-care group <i>those<\/i> guys are!\u201d Surprisingly enough, however, the good folks at TechNet \u2013 and at Microsoft in general \u2013 don\u2019t take a joke quite as well as you might think. Not that we don\u2019t do funny things here all the time; we do. It\u2019s just that most of them weren\u2019t <i>supposed<\/i> to be funny.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>So, once again, no April Fool\u2019s Day edition of the Script Center. (Will there be such an edition next year? Let\u2019s put it this way: not if the Scripting Son is still enrolled in college.) That\u2019s a bit of a disappointment for the Scripting Guy who writes this column, but most people won\u2019t know the difference. After all, most people who read this column probably think, \u201cIt must be April Fool\u2019s Day again. This can\u2019t possibly be a <i>real<\/i> column about system administration scripting!\u201d<\/p>\n<p>And yet, it is. To prove it to you, here\u2019s a script that can open an alternate home page if the default page (i.e., the company intranet site) isn\u2019t available: <\/p>\n<pre class=\"codeSample\">strWebSite = \"intranet\"\n\nSet objShell = CreateObject(\"Wscript.Shell\")\n\nSet objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n\nSet colItems = objWMIService.ExecQuery _\n    (\"Select * from Win32_PingStatus Where Address = '\" &amp; strWebSite &amp; \"'\")\n\nFor Each objItem in colItems\n    If objItem.StatusCode = 0 Then\n        objShell.Run \"http:\/\/intranet.company.com\"\n    Else\n        objShell.Run \"http:\/\/www.microsoft.com\/technet\/scriptcenter\/default.mspx\"\n    End If\nNext\n<\/pre>\n<p>Before we go any further we should note that we know of no way to add an alternate home page to Internet Explorer. Therefore, we decided to cheat a little bit here. This script should be saved as a .VBS file, and users should be instructed to click this script any time they want to start Internet Explorer. And yes, one easy way to take care of that would be to retarget your Internet Explorer start menu shortcuts to make them run this script rather than directly open Internet Explorer.<\/p>\n<p>As for the script itself, we start out by assigning the name of the server that hosts the intranet home page to a variable named strWebSite. Alternatively, we could assign strWebSite the IP address for the home page; in other words, we could do this:<\/p>\n<pre class=\"codeSample\">strWebSite = \"192.168.1.1\"\n<\/pre>\n<p>After assigning a value to strWebSite we create an instance of the <b>Wscript.Shell<\/b> object; this is the object we\u2019ll use to open a new instance of Internet Explorer. Or \u2013 gasp! \u2013 a new instance of FireFox or Opera or whatever else your default Web browser might be. (But if you aren\u2019t using Internet Explorer please <i>don\u2019t<\/i> tell us that; you\u2019ll make the Scripting Editor cry.)<\/p>\n<p>From there we connect to the WMI service on the local computer, then use this line of code (and the <b>Win32_PingStatus<\/b> class) to ping \u2013 in this case \u2013 the computer <i>intranet<\/i>:<\/p>\n<pre class=\"codeSample\">Set colItems = objWMIService.ExecQuery _\n    (\"Select * from Win32_PingStatus Where Address = '\" &amp; strWebSite &amp; \"'\")\n<\/pre>\n<p>The Win32_PingStatus class will return a property value \u2013 <b>StatusCode<\/b> \u2013 that tells us whether we were able to successfully ping the computer in question. If the StatusCode equals 0 that means our ping attempt succeeded; if the StatusCode is anything <i>but<\/i> 0 that means that the ping attempt failed. What does all that mean? It means that we can determine whether or not the computer <i>intranet<\/i> is available to us by doing two things: 1) setting up a For Each loop to loop through the collection of ping data returned by Win32_PingStatus; and, 2) inside that loop checking to see if StatusCode is equal to 0:<\/p>\n<pre class=\"codeSample\">If objItem.StatusCode = 0 Then\n<\/pre>\n<p>If the StatusCode <i>is<\/i> equal to 0 that means we\u2019re on the intranet; consequently, we use the following line of code, the <b>Run<\/b> method, to open our intranet home page:<\/p>\n<pre class=\"codeSample\">objShell.Run \"http:\/\/intranet.company.com\"\n<\/pre>\n<p>If the StatusCode is <i>not<\/i> equal to 0 that means we aren\u2019t on the intranet. In that case, we open an alternate home page:<\/p>\n<pre class=\"codeSample\">objShell.Run \"http:\/\/www.microsoft.com\/technet\/scriptcenter\/default.mspx\"\n<\/pre>\n<p>As a matter of fact that <i>is<\/i> the Script Center home page. If you can\u2019t reach your intranet home page do you <i>have<\/i> to open the Script Center home page? No, of course not \u2013 uh, yes, yes you do. In fact, you should <i>always<\/i> open the Script Center home page before you do anything else. If you don\u2019t, well, who knows what terrible things might happen?<\/p>\n<table id=\"EEG\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. Well, OK, most likely <i>nothing<\/i> terrible will happen. We just want to get as many page views as we can, one way or the other.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The preceding script works pretty well, and it works pretty fast; that\u2019s due primarily to the fact that the Ping command works pretty fast. However, there are a couple of possible drawbacks to this script. For one, you <i>do<\/i> have to know the name (or IP address) of the server where your intranet home page resides; it\u2019s not going to work to try and ping an actual Web page (like http:\/\/intranet\/company\/com\/default.htm). In addition, the Win32_PingStatus class didn\u2019t exist until Windows XP came around. If you have any computers running Windows 2000, well, they aren\u2019t going to be able to use this script.<\/p>\n<p>Which is why we\u2019re offering a backup plan. This script uses the <b>MSXML2.XMLHTTP<\/b> object to try to connect to an actual Web page: http:\/\/intranet\/company\/com\/default.htm. If the connection succeeds (that is, if the <b>Open<\/b> method returns a <b>StatusText<\/b> value equal to <i>OK<\/i>) we go ahead and open that intranet page. If StatusText turns out to be anything other than <i>OK<\/i> we open the Script Center home page instead. Here\u2019s what our Plan B script looks like:<\/p>\n<pre class=\"codeSample\">On Error Resume Next\n\nSet objShell = CreateObject(\"Wscript.Shell\")\n\nstrURL = \"http:\/\/intranet.company.com\/default.htm\"\n\nSet objHTTP = CreateObject(\"MSXML2.XMLHTTP\") \nobjHTTP.Open \"GET\", strURL, FALSE\nobjHTTP.Send\n\nIf objHTTP.StatusText = \"OK\" Then\n    objShell.Run \"http:\/\/intranet.company.com\"\nElse\n    objShell.Run \"http:\/\/www.microsoft.com\/technet\/scriptcenter\/default.mspx\"\nEnd If\n<\/pre>\n<p>This script <i>will<\/i> run on Windows 2000, and it <i>does<\/i> allow you to connect to a Web page rather than a server. The drawback? It can be considerably slower than the Ping script. If the Ping script takes 10 seconds to complete, the backup script might take 30 seconds to complete. Just something to keep in mind.<\/p>\n<p>We hope you\u2019ll find this useful, JF. Like we said, it\u2019s a bit of a workaround, but it <i>does<\/i> work.<\/p>\n<p>Because our mission is to educate people, and to keep everyone informed on the hot topics in system administration, we should note that the origins of April Fool\u2019s Day are enshrouded in mystery. One theory suggests that the custom began in France in 1564, when the country decided to start the calendar year at the beginning of January rather than the end of March. Not everyone was enamored with that decision, and a number of people stubbornly clung to the old calendar, continuing to celebrate the \u201cNew Year\u201d during the week of March 25 through April 1. Pranksters would play tricks on these old stick-in-the-mud types, primarily by attaching paper fish to their backs.<\/p>\n<p>Those wacky Frenchmen, eh? Of course, in their defense, this <i>was<\/i> 1564. Truly funny stuff probably hadn\u2019t been invented yet.<\/p>\n<p>By the way, the Vista QuarterPounder with Cheese will still include a hamburger, cheese, onions, pickles, ketchup and mustard. Or at least it will in the US. In Europe the EU will no doubt require us to sell a stripped-down version of the Vista QuarterPounder that will include only the bun; consumers will then be free to shop elsewhere for hamburger, cheese, onions, pickles, ketchup and mustard of their choice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! In our company we hardcode everyone\u2019s computer to use our intranet site as their Internet Explorer home page. All our users use laptop computers, however, and when they take the machines home with them and try to surf the Web they always start off with a Page Not Found error; that\u2019s because [&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":[17,3,167,5],"class_list":["post-55873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-internet-explorer","tag-scripting-guy","tag-using-the-internet","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! In our company we hardcode everyone\u2019s computer to use our intranet site as their Internet Explorer home page. All our users use laptop computers, however, and when they take the machines home with them and try to surf the Web they always start off with a Page Not Found error; that\u2019s because [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55873","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=55873"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55873\/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=55873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=55873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=55873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}