{"id":18,"date":"2009-02-03T17:59:00","date_gmt":"2009-02-03T22:59:00","guid":{"rendered":"http:\/\/blog.bitsofgenius.com\/?p=18"},"modified":"2011-01-26T12:38:34","modified_gmt":"2011-01-26T16:38:34","slug":"hibernating-or-switching-network-connections-part-2","status":"publish","type":"post","link":"https:\/\/blog.bitsofgenius.com\/?p=18","title":{"rendered":"Hibernating or switching network connections&#8230; Part 2"},"content":{"rendered":"<p>In my previous post about RDC, I didn&#8217;t fully like the batch file I wrote which required me to specify a parameter for swapping connections, versus hibernating.\u00a0 In fact, my favorite batch file is one where the action can be specified by the operator, or on the command line directly as a parameter.<\/p>\n<p>So I rewrote the COMMSWAP.bat process to do just that. \u00a0 If you launch it with no parameters, it displays a list of options which the operator can select with a letter and pressing ENTER.\u00a0 If it launched with a parameter, it will directly execute the action (useful for schedule or other event launches).<\/p>\n<p>The functionality hasn&#8217;t changed.\u00a0 You can also see an example of how SET \/P variable=&#8221;prompt&#8221; is used to prompt the user and record the answer.\u00a0 Enjoy.<\/p>\n<p>(Commswap.bat)<\/p>\n<pre lang=\"text\" line=\"1\" escaped=\"true\">\r\n@echo off\r\n\r\nREM CommSwap.bat -- release network resources (IP addresses), optionally put the laptop\r\nREM into hibernation or shutdown. Reads the command line argument, or prompts user if no argument supplied.\r\nREM\r\nREM CommSwap.bat s   -- (swap) release network resources, wait 5 seconds, then renew resources.\r\nREM CommSwap.bat h   -- (hibernate) release network resources, then hibernate.\r\nREM\r\n\r\nset xAction=%1\r\nif not \"%1\" == \"\" goto CHECKPARM\r\n\r\n:ASK\r\necho.\r\necho Network resource release, with optional renew.  Use this process when\r\necho switching between wireless and wired connections, or to gracefully\r\necho prepare the computer to hibernate before changing location.\r\necho.\r\necho Select from the following:\r\necho.\r\necho S -- (Swap) Release all adapters, wait 5 seconds, the renew all adapters.\r\necho H -- (Hibernate) Release all adapters, then initiate hibernation.\r\necho X -- Exit: don't do anything.\r\necho.\r\nset \/P xAction=\"Enter your choice: \"\r\n\r\n:CHECKPARM\r\nif \/I \"%xAction%\" == \"h\" goto OK\r\nif \/I \"%xAction%\" == \"s\" goto OK\r\nif \/I \"%xAction%\" == \"x\" exit\r\n\r\necho.\r\necho Command \"%xAction%\" not understood.. please try again.\r\ngoto ASK\r\n\r\n:OK\r\n\r\nipconfig \/release *\r\n\r\nif \/I \"%xAction%\" == \"h\" start rundll32 Powrprof.dll,SetSuspendState\r\nif \/I \"%xAction%\" == \"h\" exit\r\n\r\necho Waiting 5 seconds for you to disconnect a network cable or\r\necho turn off the wireless connection.\r\necho.\r\necho WScript.Sleep (5000) &gt; c:\\$$tmp$$.vbs\r\ncscript \/\/nologo \/\/b c:\\$$tmp$$.vbs\r\ndel c:\\$$tmp$$.vbs\r\n\r\nipconfig \/renew *\r\n\r\nexit\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post about RDC, I didn&#8217;t fully like the batch file I wrote which required me to specify a parameter for swapping connections, versus hibernating.\u00a0 In fact, my favorite batch file is one where the action can be specified by the operator, or on the command line directly as a parameter. So I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-technologynetworking"],"_links":{"self":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":1,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":413,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions\/413"}],"wp:attachment":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}